create-universal-ai-context 2.0.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/LICENSE +21 -0
- package/README.md +171 -0
- package/bin/create-ai-context.js +337 -0
- package/lib/adapters/antigravity.js +160 -0
- package/lib/adapters/claude.js +122 -0
- package/lib/adapters/cline.js +111 -0
- package/lib/adapters/copilot.js +117 -0
- package/lib/adapters/index.js +69 -0
- package/lib/ai-context-generator.js +234 -0
- package/lib/ai-orchestrator.js +431 -0
- package/lib/call-tracer.js +444 -0
- package/lib/detector.js +726 -0
- package/lib/environment-detector.js +239 -0
- package/lib/index.js +310 -0
- package/lib/installer.js +418 -0
- package/lib/migrate.js +319 -0
- package/lib/placeholder.js +541 -0
- package/lib/prompts.js +287 -0
- package/lib/spinner.js +60 -0
- package/lib/static-analyzer.js +729 -0
- package/lib/template-populator.js +843 -0
- package/lib/template-renderer.js +382 -0
- package/lib/validate.js +155 -0
- package/package.json +70 -0
- package/templates/AI_CONTEXT.md.template +245 -0
- package/templates/base/README.md +257 -0
- package/templates/base/RPI_WORKFLOW_PLAN.md +320 -0
- package/templates/base/agents/api-developer.md +76 -0
- package/templates/base/agents/context-engineer.md +525 -0
- package/templates/base/agents/core-architect.md +76 -0
- package/templates/base/agents/database-ops.md +76 -0
- package/templates/base/agents/deployment-ops.md +76 -0
- package/templates/base/agents/integration-hub.md +76 -0
- package/templates/base/analytics/README.md +114 -0
- package/templates/base/automation/config.json +58 -0
- package/templates/base/automation/generators/code-mapper.js +308 -0
- package/templates/base/automation/generators/index-builder.js +321 -0
- package/templates/base/automation/hooks/post-commit.sh +83 -0
- package/templates/base/automation/hooks/pre-commit.sh +103 -0
- package/templates/base/ci-templates/README.md +108 -0
- package/templates/base/ci-templates/github-actions/context-check.yml +144 -0
- package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -0
- package/templates/base/commands/analytics.md +238 -0
- package/templates/base/commands/auto-sync.md +172 -0
- package/templates/base/commands/collab.md +194 -0
- package/templates/base/commands/help.md +450 -0
- package/templates/base/commands/rpi-implement.md +115 -0
- package/templates/base/commands/rpi-plan.md +93 -0
- package/templates/base/commands/rpi-research.md +88 -0
- package/templates/base/commands/session-resume.md +144 -0
- package/templates/base/commands/session-save.md +112 -0
- package/templates/base/commands/validate-all.md +77 -0
- package/templates/base/commands/verify-docs-current.md +86 -0
- package/templates/base/config/base.json +57 -0
- package/templates/base/config/environments/development.json +13 -0
- package/templates/base/config/environments/production.json +17 -0
- package/templates/base/config/environments/staging.json +13 -0
- package/templates/base/config/local.json.example +21 -0
- package/templates/base/context/.meta/generated-at.json +18 -0
- package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -0
- package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -0
- package/templates/base/context/FILE_OWNERSHIP.md +57 -0
- package/templates/base/context/INTEGRATION_POINTS.md +92 -0
- package/templates/base/context/KNOWN_GOTCHAS.md +195 -0
- package/templates/base/context/TESTING_MAP.md +95 -0
- package/templates/base/context/WORKFLOW_INDEX.md +129 -0
- package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -0
- package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -0
- package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -0
- package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -0
- package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -0
- package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -0
- package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -0
- package/templates/base/knowledge/README.md +98 -0
- package/templates/base/knowledge/sessions/README.md +88 -0
- package/templates/base/knowledge/sessions/TEMPLATE.md +150 -0
- package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -0
- package/templates/base/knowledge/shared/decisions/README.md +49 -0
- package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -0
- package/templates/base/knowledge/shared/patterns/README.md +62 -0
- package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -0
- package/templates/base/plans/PLAN_TEMPLATE.md +250 -0
- package/templates/base/plans/active/.gitkeep +0 -0
- package/templates/base/plans/completed/.gitkeep +0 -0
- package/templates/base/research/RESEARCH_TEMPLATE.md +153 -0
- package/templates/base/research/active/.gitkeep +0 -0
- package/templates/base/research/completed/.gitkeep +0 -0
- package/templates/base/schemas/agent.schema.json +141 -0
- package/templates/base/schemas/anchors.schema.json +54 -0
- package/templates/base/schemas/automation.schema.json +93 -0
- package/templates/base/schemas/command.schema.json +134 -0
- package/templates/base/schemas/hashes.schema.json +40 -0
- package/templates/base/schemas/manifest.schema.json +117 -0
- package/templates/base/schemas/plan.schema.json +136 -0
- package/templates/base/schemas/research.schema.json +115 -0
- package/templates/base/schemas/roles.schema.json +34 -0
- package/templates/base/schemas/session.schema.json +77 -0
- package/templates/base/schemas/settings.schema.json +244 -0
- package/templates/base/schemas/staleness.schema.json +53 -0
- package/templates/base/schemas/team-config.schema.json +42 -0
- package/templates/base/schemas/workflow.schema.json +126 -0
- package/templates/base/session/checkpoints/.gitkeep +2 -0
- package/templates/base/session/current/state.json +20 -0
- package/templates/base/session/history/.gitkeep +2 -0
- package/templates/base/settings.json +3 -0
- package/templates/base/standards/COMPATIBILITY.md +219 -0
- package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -0
- package/templates/base/standards/QUALITY_CHECKLIST.md +211 -0
- package/templates/base/standards/README.md +66 -0
- package/templates/base/sync/anchors.json +6 -0
- package/templates/base/sync/hashes.json +6 -0
- package/templates/base/sync/staleness.json +10 -0
- package/templates/base/team/README.md +168 -0
- package/templates/base/team/config.json +79 -0
- package/templates/base/team/roles.json +145 -0
- package/templates/base/tools/bin/claude-context.js +151 -0
- package/templates/base/tools/lib/anchor-resolver.js +276 -0
- package/templates/base/tools/lib/config-loader.js +363 -0
- package/templates/base/tools/lib/detector.js +350 -0
- package/templates/base/tools/lib/diagnose.js +206 -0
- package/templates/base/tools/lib/drift-detector.js +373 -0
- package/templates/base/tools/lib/errors.js +199 -0
- package/templates/base/tools/lib/index.js +36 -0
- package/templates/base/tools/lib/init.js +192 -0
- package/templates/base/tools/lib/logger.js +230 -0
- package/templates/base/tools/lib/placeholder.js +201 -0
- package/templates/base/tools/lib/session-manager.js +354 -0
- package/templates/base/tools/lib/validate.js +521 -0
- package/templates/base/tools/package.json +49 -0
- package/templates/handlebars/antigravity.hbs +337 -0
- package/templates/handlebars/claude.hbs +184 -0
- package/templates/handlebars/cline.hbs +63 -0
- package/templates/handlebars/copilot.hbs +131 -0
- package/templates/handlebars/partials/gotcha-list.hbs +11 -0
- package/templates/handlebars/partials/header.hbs +3 -0
- package/templates/handlebars/partials/workflow-summary.hbs +16 -0
package/lib/detector.js
ADDED
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Context Engineering - Tech Stack Detector
|
|
3
|
+
*
|
|
4
|
+
* Auto-detects technology stack from project files.
|
|
5
|
+
* Enhanced with LOC counting, file purpose classification, and deeper analysis.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { glob } = require('glob');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* File purpose classification patterns
|
|
14
|
+
*/
|
|
15
|
+
const FILE_PURPOSE_PATTERNS = {
|
|
16
|
+
controller: {
|
|
17
|
+
patterns: [/controller/i, /handler/i, /endpoint/i],
|
|
18
|
+
directories: ['controllers', 'handlers', 'api', 'endpoints'],
|
|
19
|
+
keywords: ['@Controller', 'def handle', 'func Handle', 'router.']
|
|
20
|
+
},
|
|
21
|
+
model: {
|
|
22
|
+
patterns: [/model/i, /entity/i, /schema/i],
|
|
23
|
+
directories: ['models', 'entities', 'schemas', 'domain'],
|
|
24
|
+
keywords: ['mongoose.Schema', 'class Model', 'BaseModel', '@Entity']
|
|
25
|
+
},
|
|
26
|
+
service: {
|
|
27
|
+
patterns: [/service/i, /usecase/i],
|
|
28
|
+
directories: ['services', 'usecases', 'application'],
|
|
29
|
+
keywords: ['@Service', '@Injectable', 'class Service']
|
|
30
|
+
},
|
|
31
|
+
repository: {
|
|
32
|
+
patterns: [/repository/i, /repo/i, /dal/i],
|
|
33
|
+
directories: ['repositories', 'repos', 'dal', 'data'],
|
|
34
|
+
keywords: ['@Repository', 'class Repository', 'def find']
|
|
35
|
+
},
|
|
36
|
+
middleware: {
|
|
37
|
+
patterns: [/middleware/i, /interceptor/i, /guard/i],
|
|
38
|
+
directories: ['middleware', 'middlewares', 'interceptors', 'guards'],
|
|
39
|
+
keywords: ['next()', 'req, res, next', '@Middleware']
|
|
40
|
+
},
|
|
41
|
+
config: {
|
|
42
|
+
patterns: [/config/i, /settings/i, /env/i],
|
|
43
|
+
directories: ['config', 'configuration', 'settings'],
|
|
44
|
+
keywords: ['process.env', 'os.environ', 'Config', 'Settings']
|
|
45
|
+
},
|
|
46
|
+
util: {
|
|
47
|
+
patterns: [/util/i, /helper/i, /common/i, /lib/i],
|
|
48
|
+
directories: ['utils', 'utilities', 'helpers', 'common', 'lib', 'shared'],
|
|
49
|
+
keywords: ['export function', 'module.exports', 'def ']
|
|
50
|
+
},
|
|
51
|
+
test: {
|
|
52
|
+
patterns: [/test/i, /spec/i, /__test__/i],
|
|
53
|
+
directories: ['tests', 'test', '__tests__', 'spec', 'specs'],
|
|
54
|
+
keywords: ['describe(', 'it(', 'test(', 'def test_', 'func Test']
|
|
55
|
+
},
|
|
56
|
+
migration: {
|
|
57
|
+
patterns: [/migration/i, /migrate/i],
|
|
58
|
+
directories: ['migrations', 'migrate', 'db/migrate'],
|
|
59
|
+
keywords: ['up()', 'down()', 'def change', 'CreateTable']
|
|
60
|
+
},
|
|
61
|
+
route: {
|
|
62
|
+
patterns: [/route/i, /router/i, /url/i],
|
|
63
|
+
directories: ['routes', 'routers', 'urls'],
|
|
64
|
+
keywords: ['router.', 'app.get', 'path(', '@app.']
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Tech stack detection signatures
|
|
70
|
+
*/
|
|
71
|
+
const TECH_SIGNATURES = {
|
|
72
|
+
// Languages
|
|
73
|
+
languages: {
|
|
74
|
+
python: {
|
|
75
|
+
files: ['requirements.txt', 'pyproject.toml', 'setup.py', 'Pipfile', 'poetry.lock'],
|
|
76
|
+
extensions: ['.py'],
|
|
77
|
+
},
|
|
78
|
+
javascript: {
|
|
79
|
+
files: ['package.json', 'yarn.lock', 'pnpm-lock.yaml'],
|
|
80
|
+
extensions: ['.js', '.mjs', '.cjs'],
|
|
81
|
+
},
|
|
82
|
+
typescript: {
|
|
83
|
+
files: ['tsconfig.json'],
|
|
84
|
+
extensions: ['.ts', '.tsx'],
|
|
85
|
+
},
|
|
86
|
+
go: {
|
|
87
|
+
files: ['go.mod', 'go.sum'],
|
|
88
|
+
extensions: ['.go'],
|
|
89
|
+
},
|
|
90
|
+
rust: {
|
|
91
|
+
files: ['Cargo.toml', 'Cargo.lock'],
|
|
92
|
+
extensions: ['.rs'],
|
|
93
|
+
},
|
|
94
|
+
java: {
|
|
95
|
+
files: ['pom.xml', 'build.gradle', 'build.gradle.kts'],
|
|
96
|
+
extensions: ['.java'],
|
|
97
|
+
},
|
|
98
|
+
csharp: {
|
|
99
|
+
files: ['*.csproj', '*.sln'],
|
|
100
|
+
extensions: ['.cs'],
|
|
101
|
+
},
|
|
102
|
+
ruby: {
|
|
103
|
+
files: ['Gemfile', 'Gemfile.lock'],
|
|
104
|
+
extensions: ['.rb'],
|
|
105
|
+
},
|
|
106
|
+
php: {
|
|
107
|
+
files: ['composer.json', 'composer.lock'],
|
|
108
|
+
extensions: ['.php'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
// Frameworks
|
|
113
|
+
frameworks: {
|
|
114
|
+
// Python
|
|
115
|
+
fastapi: {
|
|
116
|
+
language: 'python',
|
|
117
|
+
patterns: ['fastapi', 'FastAPI', '@router', 'APIRouter'],
|
|
118
|
+
files: [],
|
|
119
|
+
},
|
|
120
|
+
django: {
|
|
121
|
+
language: 'python',
|
|
122
|
+
patterns: ['django.conf', 'INSTALLED_APPS', 'from django'],
|
|
123
|
+
files: ['manage.py'],
|
|
124
|
+
},
|
|
125
|
+
flask: {
|
|
126
|
+
language: 'python',
|
|
127
|
+
patterns: ['Flask(__name__)', '@app.route', 'from flask'],
|
|
128
|
+
files: [],
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// JavaScript/TypeScript
|
|
132
|
+
react: {
|
|
133
|
+
language: 'javascript',
|
|
134
|
+
patterns: ['react', 'React', 'useState', 'useEffect'],
|
|
135
|
+
packageDeps: ['react', 'react-dom'],
|
|
136
|
+
},
|
|
137
|
+
nextjs: {
|
|
138
|
+
language: 'javascript',
|
|
139
|
+
patterns: ['next/'],
|
|
140
|
+
files: ['next.config.js', 'next.config.mjs'],
|
|
141
|
+
packageDeps: ['next'],
|
|
142
|
+
},
|
|
143
|
+
express: {
|
|
144
|
+
language: 'javascript',
|
|
145
|
+
patterns: ['express()', 'app.use', 'app.get', 'router.'],
|
|
146
|
+
packageDeps: ['express'],
|
|
147
|
+
},
|
|
148
|
+
nestjs: {
|
|
149
|
+
language: 'typescript',
|
|
150
|
+
patterns: ['@nestjs/', '@Controller', '@Injectable'],
|
|
151
|
+
packageDeps: ['@nestjs/core'],
|
|
152
|
+
},
|
|
153
|
+
vue: {
|
|
154
|
+
language: 'javascript',
|
|
155
|
+
patterns: ['<template>', 'Vue.'],
|
|
156
|
+
packageDeps: ['vue'],
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
// Go
|
|
160
|
+
gin: {
|
|
161
|
+
language: 'go',
|
|
162
|
+
patterns: ['gin.', 'gin-gonic'],
|
|
163
|
+
files: [],
|
|
164
|
+
},
|
|
165
|
+
echo: {
|
|
166
|
+
language: 'go',
|
|
167
|
+
patterns: ['echo.', 'labstack/echo'],
|
|
168
|
+
files: [],
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
// Ruby
|
|
172
|
+
rails: {
|
|
173
|
+
language: 'ruby',
|
|
174
|
+
patterns: ['Rails.application', 'ActionController', 'ActiveRecord'],
|
|
175
|
+
files: ['config/routes.rb'],
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
// Rust
|
|
179
|
+
actix: {
|
|
180
|
+
language: 'rust',
|
|
181
|
+
patterns: ['actix_web', 'actix-web'],
|
|
182
|
+
files: [],
|
|
183
|
+
},
|
|
184
|
+
axum: {
|
|
185
|
+
language: 'rust',
|
|
186
|
+
patterns: ['axum::'],
|
|
187
|
+
files: [],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
// Databases
|
|
192
|
+
databases: {
|
|
193
|
+
postgresql: {
|
|
194
|
+
patterns: ['postgresql', 'postgres', 'psycopg', 'pg'],
|
|
195
|
+
envVars: ['DATABASE_URL', 'POSTGRES_'],
|
|
196
|
+
},
|
|
197
|
+
mysql: {
|
|
198
|
+
patterns: ['mysql', 'mariadb'],
|
|
199
|
+
envVars: ['MYSQL_'],
|
|
200
|
+
},
|
|
201
|
+
mongodb: {
|
|
202
|
+
patterns: ['mongodb', 'mongoose', 'pymongo'],
|
|
203
|
+
envVars: ['MONGO_'],
|
|
204
|
+
},
|
|
205
|
+
redis: {
|
|
206
|
+
patterns: ['redis', 'ioredis'],
|
|
207
|
+
envVars: ['REDIS_'],
|
|
208
|
+
},
|
|
209
|
+
sqlite: {
|
|
210
|
+
patterns: ['sqlite', 'sqlite3'],
|
|
211
|
+
files: ['*.db', '*.sqlite'],
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Entry point patterns for different frameworks
|
|
218
|
+
*/
|
|
219
|
+
const ENTRY_POINT_PATTERNS = {
|
|
220
|
+
express: {
|
|
221
|
+
regex: /app\.(get|post|put|delete|patch)\s*\(\s*['"`]([^'"`]+)['"`]/g,
|
|
222
|
+
extractor: (match) => ({ method: match[1].toUpperCase(), route: match[2] })
|
|
223
|
+
},
|
|
224
|
+
fastapi: {
|
|
225
|
+
regex: /@app\.(get|post|put|delete|patch)\s*\(\s*['"`]([^'"`]+)['"`]/g,
|
|
226
|
+
extractor: (match) => ({ method: match[1].toUpperCase(), route: match[2] })
|
|
227
|
+
},
|
|
228
|
+
nextjs: {
|
|
229
|
+
regex: /export\s+(async\s+)?function\s+(GET|POST|PUT|DELETE|PATCH)/g,
|
|
230
|
+
extractor: (match) => ({ method: match[2], route: 'app-router' })
|
|
231
|
+
},
|
|
232
|
+
django: {
|
|
233
|
+
regex: /path\s*\(\s*['"`]([^'"`]+)['"`]/g,
|
|
234
|
+
extractor: (match) => ({ method: 'ANY', route: match[1] })
|
|
235
|
+
},
|
|
236
|
+
rails: {
|
|
237
|
+
regex: /(get|post|put|delete|patch)\s+['"`]([^'"`]+)['"`]/g,
|
|
238
|
+
extractor: (match) => ({ method: match[1].toUpperCase(), route: match[2] })
|
|
239
|
+
},
|
|
240
|
+
nestjs: {
|
|
241
|
+
regex: /@(Get|Post|Put|Delete|Patch)\s*\(\s*['"`]?([^'"`)\s]*)['"`]?\s*\)/g,
|
|
242
|
+
extractor: (match) => ({ method: match[1].toUpperCase(), route: match[2] || '/' })
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Count lines of code in a file
|
|
248
|
+
* @param {string} filePath - Path to file
|
|
249
|
+
* @returns {object} LOC statistics
|
|
250
|
+
*/
|
|
251
|
+
function countLinesOfCode(filePath) {
|
|
252
|
+
try {
|
|
253
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
254
|
+
const lines = content.split('\n');
|
|
255
|
+
|
|
256
|
+
let total = lines.length;
|
|
257
|
+
let code = 0;
|
|
258
|
+
let comments = 0;
|
|
259
|
+
let blank = 0;
|
|
260
|
+
|
|
261
|
+
let inBlockComment = false;
|
|
262
|
+
|
|
263
|
+
for (const line of lines) {
|
|
264
|
+
const trimmed = line.trim();
|
|
265
|
+
|
|
266
|
+
if (!trimmed) {
|
|
267
|
+
blank++;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Check for block comments
|
|
272
|
+
if (trimmed.startsWith('/*') || trimmed.startsWith('"""') || trimmed.startsWith("'''")) {
|
|
273
|
+
inBlockComment = true;
|
|
274
|
+
comments++;
|
|
275
|
+
if (trimmed.endsWith('*/') || (trimmed.length > 3 && (trimmed.endsWith('"""') || trimmed.endsWith("'''")))) {
|
|
276
|
+
inBlockComment = false;
|
|
277
|
+
}
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (inBlockComment) {
|
|
282
|
+
comments++;
|
|
283
|
+
if (trimmed.includes('*/') || trimmed.endsWith('"""') || trimmed.endsWith("'''")) {
|
|
284
|
+
inBlockComment = false;
|
|
285
|
+
}
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Single line comments
|
|
290
|
+
if (trimmed.startsWith('//') || trimmed.startsWith('#') || trimmed.startsWith('--')) {
|
|
291
|
+
comments++;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
code++;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return { total, code, comments, blank };
|
|
299
|
+
} catch {
|
|
300
|
+
return { total: 0, code: 0, comments: 0, blank: 0 };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Count LOC for entire project
|
|
306
|
+
* @param {string} projectRoot - Project root directory
|
|
307
|
+
* @param {string[]} extensions - File extensions to count
|
|
308
|
+
* @returns {Promise<object>} LOC statistics
|
|
309
|
+
*/
|
|
310
|
+
async function countProjectLOC(projectRoot, extensions = ['.js', '.ts', '.py', '.go', '.rb', '.rs', '.java']) {
|
|
311
|
+
const stats = {
|
|
312
|
+
total: 0,
|
|
313
|
+
code: 0,
|
|
314
|
+
comments: 0,
|
|
315
|
+
blank: 0,
|
|
316
|
+
files: 0,
|
|
317
|
+
byLanguage: {}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// Build glob pattern - use array for multiple extensions, single pattern for one
|
|
321
|
+
const patterns = extensions.map(e => `**/*${e}`);
|
|
322
|
+
const globPattern = patterns.length === 1 ? patterns[0] : `{${patterns.join(',')}}`;
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
const files = await glob(globPattern, {
|
|
326
|
+
cwd: projectRoot,
|
|
327
|
+
ignore: ['node_modules/**', 'vendor/**', '.git/**', 'dist/**', 'build/**', '__pycache__/**', '*.min.js'],
|
|
328
|
+
nodir: true
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
for (const file of files.slice(0, 200)) { // Limit to 200 files for performance
|
|
332
|
+
const filePath = path.join(projectRoot, file);
|
|
333
|
+
const ext = path.extname(file);
|
|
334
|
+
const fileLoc = countLinesOfCode(filePath);
|
|
335
|
+
|
|
336
|
+
stats.total += fileLoc.total;
|
|
337
|
+
stats.code += fileLoc.code;
|
|
338
|
+
stats.comments += fileLoc.comments;
|
|
339
|
+
stats.blank += fileLoc.blank;
|
|
340
|
+
stats.files++;
|
|
341
|
+
|
|
342
|
+
// Track by language
|
|
343
|
+
if (!stats.byLanguage[ext]) {
|
|
344
|
+
stats.byLanguage[ext] = { total: 0, code: 0, files: 0 };
|
|
345
|
+
}
|
|
346
|
+
stats.byLanguage[ext].total += fileLoc.total;
|
|
347
|
+
stats.byLanguage[ext].code += fileLoc.code;
|
|
348
|
+
stats.byLanguage[ext].files++;
|
|
349
|
+
}
|
|
350
|
+
} catch {
|
|
351
|
+
// Ignore glob errors
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return stats;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Classify file purpose
|
|
359
|
+
* @param {string} filePath - Relative file path
|
|
360
|
+
* @param {string} content - File content (optional, for deeper analysis)
|
|
361
|
+
* @returns {string} File purpose category
|
|
362
|
+
*/
|
|
363
|
+
function classifyFilePurpose(filePath, content = null) {
|
|
364
|
+
const lowerPath = filePath.toLowerCase();
|
|
365
|
+
const dirName = path.dirname(lowerPath);
|
|
366
|
+
const fileName = path.basename(lowerPath, path.extname(lowerPath));
|
|
367
|
+
|
|
368
|
+
for (const [purpose, config] of Object.entries(FILE_PURPOSE_PATTERNS)) {
|
|
369
|
+
// Check directory patterns
|
|
370
|
+
for (const dir of config.directories) {
|
|
371
|
+
if (dirName.includes(dir) || dirName.endsWith(dir)) {
|
|
372
|
+
return purpose;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Check filename patterns
|
|
377
|
+
for (const pattern of config.patterns) {
|
|
378
|
+
if (pattern.test(fileName) || pattern.test(lowerPath)) {
|
|
379
|
+
return purpose;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Check content keywords if content provided
|
|
384
|
+
if (content) {
|
|
385
|
+
for (const keyword of config.keywords) {
|
|
386
|
+
if (content.includes(keyword)) {
|
|
387
|
+
return purpose;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return 'other';
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Analyze file purposes in project
|
|
398
|
+
* @param {string} projectRoot - Project root
|
|
399
|
+
* @param {string[]} extensions - File extensions to analyze
|
|
400
|
+
* @returns {Promise<object>} File purpose analysis
|
|
401
|
+
*/
|
|
402
|
+
async function analyzeFilePurposes(projectRoot, extensions = ['.js', '.ts', '.py', '.go', '.rb']) {
|
|
403
|
+
const purposes = {};
|
|
404
|
+
const filesByPurpose = {};
|
|
405
|
+
|
|
406
|
+
// Build glob pattern - use array for multiple extensions, single pattern for one
|
|
407
|
+
const patterns = extensions.map(e => `**/*${e}`);
|
|
408
|
+
const globPattern = patterns.length === 1 ? patterns[0] : `{${patterns.join(',')}}`;
|
|
409
|
+
|
|
410
|
+
try {
|
|
411
|
+
const files = await glob(globPattern, {
|
|
412
|
+
cwd: projectRoot,
|
|
413
|
+
ignore: ['node_modules/**', 'vendor/**', '.git/**', 'dist/**', 'build/**', '__pycache__/**'],
|
|
414
|
+
nodir: true
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
for (const file of files.slice(0, 100)) { // Limit for performance
|
|
418
|
+
let content = null;
|
|
419
|
+
try {
|
|
420
|
+
content = fs.readFileSync(path.join(projectRoot, file), 'utf8');
|
|
421
|
+
} catch {
|
|
422
|
+
// Skip unreadable files
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const purpose = classifyFilePurpose(file, content);
|
|
426
|
+
|
|
427
|
+
if (!purposes[purpose]) {
|
|
428
|
+
purposes[purpose] = 0;
|
|
429
|
+
filesByPurpose[purpose] = [];
|
|
430
|
+
}
|
|
431
|
+
purposes[purpose]++;
|
|
432
|
+
filesByPurpose[purpose].push(file);
|
|
433
|
+
}
|
|
434
|
+
} catch {
|
|
435
|
+
// Ignore glob errors
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return { counts: purposes, files: filesByPurpose };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Detect entry points in source files
|
|
443
|
+
*/
|
|
444
|
+
async function detectEntryPoints(projectRoot, frameworks) {
|
|
445
|
+
const entryPoints = [];
|
|
446
|
+
|
|
447
|
+
for (const framework of frameworks) {
|
|
448
|
+
const pattern = ENTRY_POINT_PATTERNS[framework];
|
|
449
|
+
if (!pattern) continue;
|
|
450
|
+
|
|
451
|
+
// Get appropriate file extension
|
|
452
|
+
const lang = TECH_SIGNATURES.frameworks[framework]?.language || 'javascript';
|
|
453
|
+
const ext = TECH_SIGNATURES.languages[lang]?.extensions?.[0] || '.js';
|
|
454
|
+
|
|
455
|
+
try {
|
|
456
|
+
const files = await glob(`**/*${ext}`, {
|
|
457
|
+
cwd: projectRoot,
|
|
458
|
+
ignore: ['node_modules/**', 'vendor/**', '.git/**', 'dist/**', 'build/**', '__pycache__/**'],
|
|
459
|
+
nodir: true,
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
463
|
+
try {
|
|
464
|
+
const content = fs.readFileSync(path.join(projectRoot, file), 'utf8');
|
|
465
|
+
let match;
|
|
466
|
+
|
|
467
|
+
while ((match = pattern.regex.exec(content)) !== null) {
|
|
468
|
+
const entry = pattern.extractor(match);
|
|
469
|
+
entryPoints.push({
|
|
470
|
+
...entry,
|
|
471
|
+
file,
|
|
472
|
+
line: content.substring(0, match.index).split('\n').length,
|
|
473
|
+
framework
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
pattern.regex.lastIndex = 0; // Reset regex
|
|
477
|
+
} catch {
|
|
478
|
+
// Skip unreadable files
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
} catch {
|
|
482
|
+
// Skip glob errors
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return entryPoints;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Detect technology stack
|
|
491
|
+
*/
|
|
492
|
+
async function detectTechStack(projectRoot, options = {}) {
|
|
493
|
+
const { hint = null } = options;
|
|
494
|
+
|
|
495
|
+
const result = {
|
|
496
|
+
stack: '',
|
|
497
|
+
summary: '',
|
|
498
|
+
languages: [],
|
|
499
|
+
frameworks: [],
|
|
500
|
+
databases: [],
|
|
501
|
+
projectName: path.basename(projectRoot),
|
|
502
|
+
fileCount: 0,
|
|
503
|
+
loc: 0,
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// If hint provided, use it
|
|
507
|
+
if (hint) {
|
|
508
|
+
result.stack = hint;
|
|
509
|
+
result.summary = hint;
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Detect languages
|
|
514
|
+
for (const [lang, signature] of Object.entries(TECH_SIGNATURES.languages)) {
|
|
515
|
+
// Check for signature files
|
|
516
|
+
for (const sigFile of signature.files) {
|
|
517
|
+
if (fs.existsSync(path.join(projectRoot, sigFile))) {
|
|
518
|
+
if (!result.languages.includes(lang)) {
|
|
519
|
+
result.languages.push(lang);
|
|
520
|
+
}
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Check for file extensions
|
|
526
|
+
if (signature.extensions) {
|
|
527
|
+
for (const ext of signature.extensions) {
|
|
528
|
+
try {
|
|
529
|
+
const files = await glob(`**/*${ext}`, {
|
|
530
|
+
cwd: projectRoot,
|
|
531
|
+
ignore: ['node_modules/**', 'vendor/**', '.git/**', 'dist/**', 'build/**'],
|
|
532
|
+
nodir: true,
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
if (files.length > 0) {
|
|
536
|
+
if (!result.languages.includes(lang)) {
|
|
537
|
+
result.languages.push(lang);
|
|
538
|
+
}
|
|
539
|
+
result.fileCount += files.length;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
} catch {
|
|
543
|
+
// Ignore glob errors
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// Detect frameworks
|
|
550
|
+
for (const [framework, signature] of Object.entries(TECH_SIGNATURES.frameworks)) {
|
|
551
|
+
// Check for package.json dependencies
|
|
552
|
+
if (signature.packageDeps) {
|
|
553
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
554
|
+
if (fs.existsSync(pkgPath)) {
|
|
555
|
+
try {
|
|
556
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
557
|
+
const allDeps = {
|
|
558
|
+
...pkg.dependencies,
|
|
559
|
+
...pkg.devDependencies,
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
for (const dep of signature.packageDeps) {
|
|
563
|
+
if (allDeps[dep]) {
|
|
564
|
+
if (!result.frameworks.includes(framework)) {
|
|
565
|
+
result.frameworks.push(framework);
|
|
566
|
+
}
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} catch {
|
|
571
|
+
// Ignore JSON parse errors
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Check for signature files
|
|
577
|
+
if (signature.files) {
|
|
578
|
+
for (const sigFile of signature.files) {
|
|
579
|
+
if (fs.existsSync(path.join(projectRoot, sigFile))) {
|
|
580
|
+
if (!result.frameworks.includes(framework)) {
|
|
581
|
+
result.frameworks.push(framework);
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Check for patterns in source files (sample)
|
|
589
|
+
if (signature.patterns && result.languages.includes(signature.language)) {
|
|
590
|
+
// Sample a few source files
|
|
591
|
+
const ext = TECH_SIGNATURES.languages[signature.language]?.extensions?.[0];
|
|
592
|
+
if (ext) {
|
|
593
|
+
try {
|
|
594
|
+
const sampleFiles = await glob(`**/*${ext}`, {
|
|
595
|
+
cwd: projectRoot,
|
|
596
|
+
ignore: ['node_modules/**', 'vendor/**', '.git/**'],
|
|
597
|
+
nodir: true,
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// Check first 5 files
|
|
601
|
+
for (const file of sampleFiles.slice(0, 5)) {
|
|
602
|
+
try {
|
|
603
|
+
const content = fs.readFileSync(path.join(projectRoot, file), 'utf8');
|
|
604
|
+
|
|
605
|
+
for (const pattern of signature.patterns) {
|
|
606
|
+
if (content.includes(pattern)) {
|
|
607
|
+
if (!result.frameworks.includes(framework)) {
|
|
608
|
+
result.frameworks.push(framework);
|
|
609
|
+
}
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
} catch {
|
|
614
|
+
// Ignore file read errors
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
} catch {
|
|
618
|
+
// Ignore glob errors
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// Detect databases
|
|
625
|
+
for (const [db, signature] of Object.entries(TECH_SIGNATURES.databases)) {
|
|
626
|
+
// Check environment files
|
|
627
|
+
const envFiles = ['.env', '.env.example', '.env.local'];
|
|
628
|
+
for (const envFile of envFiles) {
|
|
629
|
+
const envPath = path.join(projectRoot, envFile);
|
|
630
|
+
if (fs.existsSync(envPath)) {
|
|
631
|
+
try {
|
|
632
|
+
const content = fs.readFileSync(envPath, 'utf8');
|
|
633
|
+
|
|
634
|
+
if (signature.envVars) {
|
|
635
|
+
for (const envVar of signature.envVars) {
|
|
636
|
+
if (content.includes(envVar)) {
|
|
637
|
+
if (!result.databases.includes(db)) {
|
|
638
|
+
result.databases.push(db);
|
|
639
|
+
}
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
} catch {
|
|
645
|
+
// Ignore read errors
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Check for patterns in config files
|
|
651
|
+
if (signature.patterns) {
|
|
652
|
+
const configFiles = ['package.json', 'requirements.txt', 'pyproject.toml', 'Cargo.toml'];
|
|
653
|
+
for (const configFile of configFiles) {
|
|
654
|
+
const configPath = path.join(projectRoot, configFile);
|
|
655
|
+
if (fs.existsSync(configPath)) {
|
|
656
|
+
try {
|
|
657
|
+
const content = fs.readFileSync(configPath, 'utf8').toLowerCase();
|
|
658
|
+
|
|
659
|
+
for (const pattern of signature.patterns) {
|
|
660
|
+
if (content.includes(pattern.toLowerCase())) {
|
|
661
|
+
if (!result.databases.includes(db)) {
|
|
662
|
+
result.databases.push(db);
|
|
663
|
+
}
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
} catch {
|
|
668
|
+
// Ignore read errors
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Detect entry points for discovered frameworks
|
|
676
|
+
result.entryPoints = await detectEntryPoints(projectRoot, result.frameworks);
|
|
677
|
+
|
|
678
|
+
// Count lines of code
|
|
679
|
+
const langExtensions = result.languages.flatMap(lang =>
|
|
680
|
+
TECH_SIGNATURES.languages[lang]?.extensions || []
|
|
681
|
+
);
|
|
682
|
+
if (langExtensions.length > 0) {
|
|
683
|
+
result.loc = await countProjectLOC(projectRoot, langExtensions);
|
|
684
|
+
} else {
|
|
685
|
+
result.loc = await countProjectLOC(projectRoot);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// Analyze file purposes
|
|
689
|
+
result.filePurposes = await analyzeFilePurposes(projectRoot, langExtensions.length > 0 ? langExtensions : undefined);
|
|
690
|
+
|
|
691
|
+
// Build stack string
|
|
692
|
+
const stackParts = [];
|
|
693
|
+
if (result.languages.length > 0) {
|
|
694
|
+
stackParts.push(result.languages.map(l => capitalize(l)).join(', '));
|
|
695
|
+
}
|
|
696
|
+
if (result.frameworks.length > 0) {
|
|
697
|
+
stackParts.push(result.frameworks.map(f => capitalize(f)).join(', '));
|
|
698
|
+
}
|
|
699
|
+
if (result.databases.length > 0) {
|
|
700
|
+
stackParts.push(result.databases.map(d => capitalize(d)).join(', '));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
result.stack = stackParts.join(' + ') || 'Unknown';
|
|
704
|
+
result.summary = result.stack;
|
|
705
|
+
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Capitalize first letter
|
|
711
|
+
*/
|
|
712
|
+
function capitalize(str) {
|
|
713
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
module.exports = {
|
|
717
|
+
detectTechStack,
|
|
718
|
+
detectEntryPoints,
|
|
719
|
+
countLinesOfCode,
|
|
720
|
+
countProjectLOC,
|
|
721
|
+
classifyFilePurpose,
|
|
722
|
+
analyzeFilePurposes,
|
|
723
|
+
TECH_SIGNATURES,
|
|
724
|
+
ENTRY_POINT_PATTERNS,
|
|
725
|
+
FILE_PURPOSE_PATTERNS,
|
|
726
|
+
};
|