forge-workflow 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/.claude/commands/dev.md +340 -340
  2. package/.claude/commands/plan.md +521 -521
  3. package/.claude/commands/premerge.md +176 -176
  4. package/.claude/commands/research.md +42 -42
  5. package/.claude/commands/review.md +442 -442
  6. package/.claude/commands/rollback.md +721 -721
  7. package/.claude/commands/ship.md +164 -164
  8. package/.claude/commands/sonarcloud.md +152 -152
  9. package/.claude/commands/status.md +48 -48
  10. package/.claude/commands/validate.md +282 -282
  11. package/.claude/commands/verify.md +221 -221
  12. package/.claude/rules/greptile-review-process.md +285 -285
  13. package/.claude/rules/workflow.md +105 -105
  14. package/.claude/scripts/greptile-resolve.sh +526 -526
  15. package/.claude/scripts/load-env.sh +32 -32
  16. package/.cline/workflows/dev.md +337 -337
  17. package/.cline/workflows/plan.md +518 -518
  18. package/.cline/workflows/premerge.md +173 -173
  19. package/.cline/workflows/research.md +39 -39
  20. package/.cline/workflows/review.md +439 -439
  21. package/.cline/workflows/rollback.md +718 -718
  22. package/.cline/workflows/ship.md +161 -161
  23. package/.cline/workflows/sonarcloud.md +146 -146
  24. package/.cline/workflows/status.md +45 -45
  25. package/.cline/workflows/validate.md +279 -279
  26. package/.cline/workflows/verify.md +218 -218
  27. package/.codex/config.toml +11 -11
  28. package/.codex/skills/dev/SKILL.md +340 -340
  29. package/.codex/skills/plan/SKILL.md +521 -521
  30. package/.codex/skills/premerge/SKILL.md +176 -176
  31. package/.codex/skills/research/SKILL.md +42 -42
  32. package/.codex/skills/review/SKILL.md +442 -442
  33. package/.codex/skills/rollback/SKILL.md +721 -721
  34. package/.codex/skills/ship/SKILL.md +164 -164
  35. package/.codex/skills/sonarcloud/SKILL.md +149 -149
  36. package/.codex/skills/status/SKILL.md +48 -48
  37. package/.codex/skills/validate/SKILL.md +282 -282
  38. package/.codex/skills/verify/SKILL.md +221 -221
  39. package/.cursor/commands/dev.md +337 -337
  40. package/.cursor/commands/plan.md +518 -518
  41. package/.cursor/commands/premerge.md +173 -173
  42. package/.cursor/commands/research.md +39 -39
  43. package/.cursor/commands/review.md +439 -439
  44. package/.cursor/commands/rollback.md +718 -718
  45. package/.cursor/commands/ship.md +161 -161
  46. package/.cursor/commands/sonarcloud.md +146 -146
  47. package/.cursor/commands/status.md +45 -45
  48. package/.cursor/commands/validate.md +279 -279
  49. package/.cursor/commands/verify.md +218 -218
  50. package/.cursor/rules/permissions-guidance.mdc +37 -37
  51. package/.forge/hooks/check-tdd.js +240 -240
  52. package/.github/PLUGIN_TEMPLATE.json +32 -32
  53. package/.github/prompts/dev.prompt.md +342 -342
  54. package/.github/prompts/plan.prompt.md +523 -523
  55. package/.github/prompts/premerge.prompt.md +178 -178
  56. package/.github/prompts/research.prompt.md +44 -44
  57. package/.github/prompts/review.prompt.md +444 -444
  58. package/.github/prompts/rollback.prompt.md +723 -723
  59. package/.github/prompts/ship.prompt.md +166 -166
  60. package/.github/prompts/sonarcloud.prompt.md +151 -151
  61. package/.github/prompts/status.prompt.md +50 -50
  62. package/.github/prompts/validate.prompt.md +284 -284
  63. package/.github/prompts/verify.prompt.md +223 -223
  64. package/.github/workflows/beads-to-github.yml +56 -0
  65. package/.github/workflows/github-to-beads.yml +97 -0
  66. package/.kilocode/workflows/dev.md +341 -341
  67. package/.kilocode/workflows/plan.md +522 -522
  68. package/.kilocode/workflows/premerge.md +177 -177
  69. package/.kilocode/workflows/research.md +43 -43
  70. package/.kilocode/workflows/review.md +443 -443
  71. package/.kilocode/workflows/rollback.md +722 -722
  72. package/.kilocode/workflows/ship.md +165 -165
  73. package/.kilocode/workflows/sonarcloud.md +150 -150
  74. package/.kilocode/workflows/status.md +49 -49
  75. package/.kilocode/workflows/validate.md +283 -283
  76. package/.kilocode/workflows/verify.md +222 -222
  77. package/.mcp.json.example +12 -12
  78. package/.opencode/commands/dev.md +340 -340
  79. package/.opencode/commands/plan.md +521 -521
  80. package/.opencode/commands/premerge.md +176 -176
  81. package/.opencode/commands/research.md +42 -42
  82. package/.opencode/commands/review.md +442 -442
  83. package/.opencode/commands/rollback.md +721 -721
  84. package/.opencode/commands/ship.md +164 -164
  85. package/.opencode/commands/sonarcloud.md +149 -149
  86. package/.opencode/commands/status.md +48 -48
  87. package/.opencode/commands/validate.md +282 -282
  88. package/.opencode/commands/verify.md +221 -221
  89. package/.roo/commands/dev.md +341 -341
  90. package/.roo/commands/plan.md +522 -522
  91. package/.roo/commands/premerge.md +177 -177
  92. package/.roo/commands/research.md +43 -43
  93. package/.roo/commands/review.md +443 -443
  94. package/.roo/commands/rollback.md +722 -722
  95. package/.roo/commands/ship.md +165 -165
  96. package/.roo/commands/sonarcloud.md +150 -150
  97. package/.roo/commands/status.md +49 -49
  98. package/.roo/commands/validate.md +283 -283
  99. package/.roo/commands/verify.md +222 -222
  100. package/AGENTS.md +175 -175
  101. package/CLAUDE.md +100 -100
  102. package/README.md +429 -416
  103. package/bin/forge-cmd.js +313 -313
  104. package/bin/forge-preflight.js +309 -309
  105. package/bin/forge.js +4596 -4303
  106. package/docs/AGENT_INSTALL_PROMPT.md +342 -342
  107. package/docs/BEADS_GITHUB_SYNC.md +251 -251
  108. package/docs/ENHANCED_ONBOARDING.md +602 -602
  109. package/docs/EXAMPLES.md +482 -482
  110. package/docs/GREPTILE_SETUP.md +400 -400
  111. package/docs/MANUAL_REVIEW_GUIDE.md +106 -106
  112. package/docs/ROADMAP.md +359 -359
  113. package/docs/SETUP.md +663 -631
  114. package/docs/TOOLCHAIN.md +630 -630
  115. package/docs/VALIDATION.md +363 -363
  116. package/install.sh +40 -1056
  117. package/lefthook.yml +39 -39
  118. package/lib/agents/README.md +198 -198
  119. package/lib/agents/claude.plugin.json +28 -28
  120. package/lib/agents/cline.plugin.json +22 -22
  121. package/lib/agents/codex.plugin.json +19 -19
  122. package/lib/agents/copilot.plugin.json +24 -24
  123. package/lib/agents/cursor.plugin.json +25 -25
  124. package/lib/agents/kilocode.plugin.json +22 -22
  125. package/lib/agents/opencode.plugin.json +20 -20
  126. package/lib/agents/roo.plugin.json +23 -23
  127. package/lib/agents-config.js +2112 -2112
  128. package/lib/beads-health-check.js +143 -0
  129. package/lib/beads-setup.js +341 -0
  130. package/lib/beads-sync-scaffold.js +260 -0
  131. package/lib/commands/dev.js +513 -513
  132. package/lib/commands/plan.js +692 -692
  133. package/lib/commands/recommend.js +119 -119
  134. package/lib/commands/ship.js +377 -377
  135. package/lib/commands/status.js +378 -378
  136. package/lib/commands/validate.js +602 -602
  137. package/lib/context-merge.js +359 -359
  138. package/lib/dep-guard/analyzer.js +294 -294
  139. package/lib/dep-guard/behavior-detector.js +98 -98
  140. package/lib/dep-guard/contract-detector.js +162 -162
  141. package/lib/dep-guard/import-detector.js +498 -498
  142. package/lib/dep-guard/path-utils.js +13 -13
  143. package/lib/dep-guard/rubric.js +120 -120
  144. package/lib/dep-guard/task-parser.js +318 -318
  145. package/lib/detect-agent.js +191 -191
  146. package/lib/detect-worktree.js +47 -47
  147. package/lib/file-hash.js +26 -26
  148. package/lib/husky-migration.js +450 -0
  149. package/lib/lefthook-check.js +65 -0
  150. package/lib/pat-setup.js +207 -0
  151. package/lib/plugin-catalog.js +350 -350
  152. package/lib/plugin-manager.js +166 -166
  153. package/lib/plugin-recommender.js +141 -141
  154. package/lib/project-discovery.js +491 -491
  155. package/lib/setup-action-log.js +139 -139
  156. package/lib/setup-summary-renderer.js +106 -106
  157. package/lib/setup-utils.js +96 -0
  158. package/lib/setup.js +192 -192
  159. package/lib/smart-merge.js +64 -0
  160. package/lib/symlink-utils.js +81 -0
  161. package/lib/workflow-profiles.js +197 -197
  162. package/package.json +131 -128
  163. package/scripts/beads-context.sh +291 -0
  164. package/scripts/beads-context.test.js +563 -0
  165. package/scripts/behavioral-judge.sh +378 -0
  166. package/scripts/benchmark.js +85 -0
  167. package/scripts/branch-protection.js +183 -0
  168. package/scripts/check-agents.js +172 -0
  169. package/scripts/commitlint.js +42 -0
  170. package/scripts/conflict-detect.sh +323 -0
  171. package/scripts/dep-guard-analyze.js +71 -0
  172. package/scripts/dep-guard.sh +811 -0
  173. package/scripts/eval_win.py +249 -0
  174. package/scripts/file-index.sh +399 -0
  175. package/scripts/github-beads-sync/comment.mjs +64 -0
  176. package/scripts/github-beads-sync/config.mjs +148 -0
  177. package/scripts/github-beads-sync/github-api.mjs +131 -0
  178. package/scripts/github-beads-sync/index.mjs +332 -0
  179. package/scripts/github-beads-sync/label-mapper.mjs +54 -0
  180. package/scripts/github-beads-sync/mapping.mjs +78 -0
  181. package/scripts/github-beads-sync/reverse-sync-cli.mjs +31 -0
  182. package/scripts/github-beads-sync/reverse-sync.mjs +138 -0
  183. package/scripts/github-beads-sync/run-bd.mjs +159 -0
  184. package/scripts/github-beads-sync/sanitize.mjs +121 -0
  185. package/scripts/github-beads-sync.config.json +26 -0
  186. package/scripts/improve-command.js +375 -0
  187. package/scripts/lib/eval-runner.js +229 -0
  188. package/scripts/lib/eval-schema.js +135 -0
  189. package/scripts/lib/eval-storage.js +78 -0
  190. package/scripts/lib/grading.js +203 -0
  191. package/scripts/lib/transcript-parser.js +63 -0
  192. package/scripts/lint.js +47 -0
  193. package/scripts/migrate-to-bun-test.js +412 -0
  194. package/scripts/run-command-eval.js +236 -0
  195. package/scripts/smart-status.sh +782 -0
  196. package/scripts/sync-commands.js +571 -0
  197. package/scripts/sync-utils.sh +460 -0
  198. package/scripts/test-dashboard.js +123 -0
  199. package/scripts/test.js +44 -0
  200. package/scripts/validate.sh +94 -0
  201. package/skills/parallel-deep-research/SKILL.md +108 -108
  202. package/skills/parallel-deep-research/evals/README.md +27 -27
  203. package/skills/parallel-deep-research/evals/evals.json +62 -62
  204. package/skills/sonarcloud-analysis/SKILL.md +171 -171
  205. package/skills/sonarcloud-analysis/evals/README.md +27 -27
  206. package/skills/sonarcloud-analysis/evals/evals.json +50 -50
  207. package/skills/sonarcloud-analysis/references/api-reference.md +466 -466
  208. package/.cursor/hooks/state/continual-learning-index.json +0 -19
  209. package/.cursor/hooks/state/continual-learning.json +0 -8
@@ -1,491 +1,491 @@
1
- /**
2
- * Project Discovery
3
- *
4
- * Auto-detects project context (framework, language, stage) from file system.
5
- */
6
-
7
- const fs = require('node:fs');
8
- const path = require('node:path');
9
- const { execFileSync } = require('node:child_process');
10
-
11
- async function detectFramework(projectPath) {
12
- try {
13
- const packageJsonPath = path.join(projectPath, 'package.json');
14
- if (!fs.existsSync(packageJsonPath)) return null;
15
-
16
- const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
17
- const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
18
-
19
- if (allDeps['next']) return 'Next.js';
20
- if (allDeps['react']) return 'React';
21
- if (allDeps['vue']) return 'Vue.js';
22
- if (allDeps['express']) return 'Express';
23
- return null;
24
- } catch (error) {
25
- // Return null if package.json doesn't exist or is invalid
26
- console.warn('Failed to detect framework:', error.message);
27
- return null;
28
- }
29
- }
30
-
31
- async function detectLanguage(projectPath) {
32
- try {
33
- const packageJsonPath = path.join(projectPath, 'package.json');
34
- if (fs.existsSync(packageJsonPath)) {
35
- const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
36
- const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
37
- if (allDeps['typescript']) return 'typescript';
38
- }
39
- return 'javascript';
40
- } catch (error) {
41
- // Default to javascript if detection fails
42
- console.warn('Failed to detect language:', error.message);
43
- return 'javascript';
44
- }
45
- }
46
-
47
- async function getGitStats(projectPath) {
48
- try {
49
- const gitDir = path.join(projectPath, '.git');
50
- if (!fs.existsSync(gitDir)) {
51
- return { commits: 0, hasReleases: false };
52
- }
53
-
54
- // SECURITY (S4036): Relies on git from PATH - Acceptable for developer CLI tool
55
- // - This is a developer tool requiring git installation
56
- // - Commands are hardcoded with no user input (no injection risk)
57
- // - stdio isolation prevents shell injection
58
- // - If PATH is compromised to inject malicious git, developer has bigger problems
59
- // - Cross-platform: absolute paths (/usr/bin/git) would break Windows/macOS variants
60
- // Use timeout to prevent hanging on slow git operations (Greptile feedback)
61
- const commitCount = execFileSync('git', ['rev-list', '--count', 'HEAD'], { // NOSONAR S4036 - hardcoded CLI command, no user input, developer tool context
62
- cwd: projectPath,
63
- encoding: 'utf8',
64
- stdio: ['pipe', 'pipe', 'pipe'],
65
- timeout: 5000 // 5 second timeout
66
- }).trim();
67
-
68
- // SECURITY (S4036): Same risk assessment as above - acceptable in developer tool context
69
- const tags = execFileSync('git', ['tag'], { // NOSONAR S4036 - hardcoded CLI command, no user input, developer tool context
70
- cwd: projectPath,
71
- encoding: 'utf8',
72
- stdio: ['pipe', 'pipe', 'pipe'],
73
- timeout: 5000 // 5 second timeout
74
- }).trim();
75
-
76
- return {
77
- commits: Number.parseInt(commitCount, 10) || 0,
78
- hasReleases: tags.split('\n').some(t => t.trim()) // Use .some() instead of .filter().length
79
- };
80
- } catch (error) {
81
- // Return defaults if git commands fail or timeout
82
- console.warn('Failed to get git stats:', error.message);
83
- return { commits: 0, hasReleases: false };
84
- }
85
- }
86
-
87
- async function detectCICD(projectPath) {
88
- const cicdPaths = [
89
- { path: '.github/workflows', type: 'GitHub Actions' },
90
- { path: '.gitlab-ci.yml', type: 'GitLab CI' }
91
- ];
92
-
93
- for (const { path: ciPath, type } of cicdPaths) {
94
- if (fs.existsSync(path.join(projectPath, ciPath))) {
95
- return { exists: true, type };
96
- }
97
- }
98
-
99
- return { exists: false, type: null };
100
- }
101
-
102
- async function getTestCoverage(projectPath) {
103
- try {
104
- const coveragePath = path.join(projectPath, 'coverage', 'coverage-summary.json');
105
- if (fs.existsSync(coveragePath)) {
106
- const coverageData = JSON.parse(await fs.promises.readFile(coveragePath, 'utf8'));
107
- // Use optional chaining for cleaner, safer access
108
- return coverageData.total?.lines?.pct || 0;
109
- }
110
-
111
- const packageJsonPath = path.join(projectPath, 'package.json');
112
- if (!fs.existsSync(packageJsonPath)) return 0;
113
-
114
- const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
115
- // Use optional chaining
116
- if (!packageJson.scripts?.test) return 0;
117
-
118
- return 50;
119
- } catch (error) {
120
- // Return 0 if coverage files are missing or invalid
121
- console.warn('Failed to get test coverage:', error.message);
122
- return 0;
123
- }
124
- }
125
-
126
- function inferStage(stats) {
127
- const { commits = 0, hasCICD = false, hasReleases = false, coverage = 0 } = stats;
128
-
129
- if (commits > 500 && hasCICD && hasReleases && coverage > 80) {
130
- return 'stable';
131
- }
132
-
133
- if (commits < 50 && !hasCICD && coverage < 30) {
134
- return 'new';
135
- }
136
-
137
- if (commits < 20) {
138
- return 'new';
139
- }
140
-
141
- return 'active';
142
- }
143
-
144
- function calculateConfidence(context) {
145
- let score = 0;
146
- if (context.framework) score += 0.3;
147
- if (context.language) score += 0.2;
148
- if (context.commits > 0) score += 0.2;
149
- if (context.hasCICD) score += 0.15;
150
- if (context.coverage > 0) score += 0.15;
151
- return Math.max(score, 0.3);
152
- }
153
-
154
- async function autoDetect(projectPath) {
155
- try {
156
- const framework = await detectFramework(projectPath);
157
- const language = await detectLanguage(projectPath);
158
- const gitStats = await getGitStats(projectPath);
159
- const cicd = await detectCICD(projectPath);
160
- const coverage = await getTestCoverage(projectPath);
161
-
162
- const context = {
163
- framework,
164
- language,
165
- commits: gitStats.commits,
166
- hasCICD: cicd.exists,
167
- cicdType: cicd.type,
168
- hasReleases: gitStats.hasReleases,
169
- coverage
170
- };
171
-
172
- const stage = inferStage(context);
173
- const confidence = calculateConfidence({ ...context, stage });
174
-
175
- return { ...context, stage, confidence };
176
- } catch (error) {
177
- // Top-level error boundary: return safe defaults if orchestration fails
178
- console.warn('Failed to auto-detect project context:', error.message);
179
- return {
180
- framework: null,
181
- language: 'javascript',
182
- commits: 0,
183
- hasCICD: false,
184
- cicdType: null,
185
- hasReleases: false,
186
- coverage: 0,
187
- stage: 'new',
188
- confidence: 0.3
189
- };
190
- }
191
- }
192
-
193
- /**
194
- * Save detected context to .forge/context.json
195
- * Normalized to always expect flat object from autoDetect() (Greptile feedback)
196
- * @param {Object} context - Flat context object with framework, language, stage, confidence
197
- * @param {string} projectPath - Project root path
198
- */
199
- async function saveContext(context, projectPath) {
200
- const forgeDir = path.join(projectPath, '.forge');
201
- const contextPath = path.join(forgeDir, 'context.json');
202
-
203
- await fs.promises.mkdir(forgeDir, { recursive: true });
204
-
205
- // Always expect flat shape from autoDetect(), build nested structure internally
206
- const data = {
207
- auto_detected: {
208
- framework: context.framework,
209
- language: context.language,
210
- stage: context.stage,
211
- confidence: context.confidence,
212
- // Include optional fields if present
213
- ...(context.commits !== undefined && { commits: context.commits }),
214
- ...(context.hasCICD !== undefined && { hasCICD: context.hasCICD }),
215
- ...(context.hasReleases !== undefined && { hasReleases: context.hasReleases }),
216
- ...(context.coverage !== undefined && { coverage: context.coverage })
217
- },
218
- user_provided: {},
219
- last_updated: new Date().toISOString()
220
- };
221
-
222
- await fs.promises.writeFile(contextPath, JSON.stringify(data, null, 2), 'utf8');
223
- }
224
-
225
- async function loadContext(projectPath) {
226
- try {
227
- const contextPath = path.join(projectPath, '.forge', 'context.json');
228
- if (!fs.existsSync(contextPath)) return null;
229
-
230
- const data = await fs.promises.readFile(contextPath, 'utf8');
231
- return JSON.parse(data);
232
- } catch (error) {
233
- // Return null if context file doesn't exist or is invalid
234
- console.warn('Failed to load context:', error.message);
235
- return null;
236
- }
237
- }
238
-
239
- /**
240
- * Detect which AI coding agents are installed/configured in the project
241
- * @param {string} projectPath - Path to the project root
242
- * @returns {Promise<string[]>} - Array of detected agent identifiers
243
- */
244
- async function detectInstalledAgents(projectPath) {
245
- const detectedAgents = [];
246
-
247
- try {
248
- // Define detection patterns for each agent
249
- const agentDetectors = [
250
- {
251
- name: 'claude',
252
- checks: [
253
- // .claude directory (primary indicator)
254
- async () => {
255
- const claudeDir = path.join(projectPath, '.claude');
256
- return fs.existsSync(claudeDir) && (await fs.promises.stat(claudeDir)).isDirectory();
257
- },
258
- // CLAUDE.md file (legacy indicator)
259
- async () => {
260
- const claudeMd = path.join(projectPath, 'CLAUDE.md');
261
- return fs.existsSync(claudeMd);
262
- }
263
- ]
264
- },
265
- {
266
- name: 'copilot',
267
- checks: [
268
- // .github/copilot-instructions.md
269
- async () => {
270
- const copilotFile = path.join(projectPath, '.github', 'copilot-instructions.md');
271
- return fs.existsSync(copilotFile);
272
- }
273
- ]
274
- },
275
- {
276
- name: 'cursor',
277
- checks: [
278
- // .cursor directory
279
- async () => {
280
- const cursorDir = path.join(projectPath, '.cursor');
281
- return fs.existsSync(cursorDir) && (await fs.promises.stat(cursorDir)).isDirectory();
282
- }
283
- ]
284
- },
285
- {
286
- name: 'kilo',
287
- checks: [
288
- // .kilo.md file
289
- async () => {
290
- const kiloMd = path.join(projectPath, '.kilo.md');
291
- return fs.existsSync(kiloMd);
292
- }
293
- ]
294
- },
295
- {
296
- name: 'opencode',
297
- checks: [
298
- // opencode.json file
299
- async () => {
300
- const opencodeJson = path.join(projectPath, 'opencode.json');
301
- return fs.existsSync(opencodeJson);
302
- }
303
- ]
304
- }
305
- ];
306
-
307
- // Check each agent
308
- for (const detector of agentDetectors) {
309
- // Check if any of the detection patterns match
310
- for (const check of detector.checks) {
311
- try {
312
- const detected = await check();
313
- if (detected) {
314
- detectedAgents.push(detector.name);
315
- break; // Agent detected, no need to check other patterns
316
- }
317
- } catch (_error) {
318
- // Ignore errors for individual checks (e.g., permission issues)
319
- continue;
320
- }
321
- }
322
- }
323
-
324
- return detectedAgents;
325
- } catch (error) {
326
- // Return empty array if detection fails entirely
327
- console.warn('Failed to detect installed agents:', error.message);
328
- return [];
329
- }
330
- }
331
-
332
- // ── Tech Stack Detection (synchronous, read-only) ──
333
-
334
- function loadPackageJsonSafe(projectPath) {
335
- try {
336
- const pkgPath = path.join(projectPath, 'package.json');
337
- if (!fs.existsSync(pkgPath)) return null;
338
- return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
339
- } catch {
340
- return null;
341
- }
342
- }
343
-
344
- function fileExists(projectPath, fileName) {
345
- return fs.existsSync(path.join(projectPath, fileName));
346
- }
347
-
348
- function detectFrameworks(deps) {
349
- const frameworks = [];
350
- const map = {
351
- next: 'nextjs', react: 'react', vue: 'vue', '@angular/core': 'angular',
352
- svelte: 'svelte', astro: 'astro', '@remix-run/node': 'remix',
353
- nuxt: 'nuxt', express: 'express', fastify: 'fastify', '@nestjs/core': 'nestjs',
354
- };
355
- for (const [dep, name] of Object.entries(map)) {
356
- if (deps[dep]) frameworks.push(name);
357
- }
358
- return frameworks;
359
- }
360
-
361
- function detectDatabases(deps) {
362
- const dbs = [];
363
- const map = {
364
- '@supabase/supabase-js': 'supabase', '@neondatabase/serverless': 'neon',
365
- convex: 'convex', '@prisma/client': 'prisma', drizzle: 'drizzle',
366
- 'drizzle-orm': 'drizzle', mongodb: 'mongodb', mongoose: 'mongodb', pg: 'postgresql',
367
- };
368
- for (const [dep, name] of Object.entries(map)) {
369
- if (deps[dep] && !dbs.includes(name)) dbs.push(name);
370
- }
371
- return dbs;
372
- }
373
-
374
- function detectAuthProviders(deps) {
375
- const auth = [];
376
- const map = {
377
- '@clerk/nextjs': 'clerk', '@clerk/clerk-react': 'clerk',
378
- 'next-auth': 'authjs', '@auth/core': 'authjs',
379
- firebase: 'firebase-auth', '@firebase/auth': 'firebase-auth',
380
- };
381
- for (const [dep, name] of Object.entries(map)) {
382
- if (deps[dep] && !auth.includes(name)) auth.push(name);
383
- }
384
- // Supabase auth detected via supabase-js
385
- if (deps['@supabase/supabase-js'] && !auth.includes('supabase-auth')) {
386
- auth.push('supabase-auth');
387
- }
388
- return auth;
389
- }
390
-
391
- function detectPaymentProviders(deps) {
392
- const payments = [];
393
- const map = {
394
- stripe: 'stripe', '@paddle/paddle-js': 'paddle',
395
- '@lemonsqueezy/lemonsqueezy.js': 'lemonsqueezy',
396
- };
397
- for (const [dep, name] of Object.entries(map)) {
398
- if (deps[dep]) payments.push(name);
399
- }
400
- return payments;
401
- }
402
-
403
- function detectTestingTools(deps) {
404
- const testing = [];
405
- const map = {
406
- vitest: 'vitest', jest: 'jest', '@playwright/test': 'playwright',
407
- cypress: 'cypress', mocha: 'mocha',
408
- };
409
- for (const [dep, name] of Object.entries(map)) {
410
- if (deps[dep]) testing.push(name);
411
- }
412
- return testing;
413
- }
414
-
415
- function detectLintingTools(deps, projectPath) {
416
- const linting = [];
417
- if (deps.eslint || fileExists(projectPath, 'eslint.config.js') || fileExists(projectPath, '.eslintrc.json')) {
418
- linting.push('eslint');
419
- }
420
- if (fileExists(projectPath, 'biome.json') || deps['@biomejs/biome']) {
421
- linting.push('biome');
422
- }
423
- if (deps.oxlint) linting.push('oxlint');
424
- if (deps.prettier || fileExists(projectPath, '.prettierrc') || fileExists(projectPath, '.prettierrc.json')) {
425
- linting.push('prettier');
426
- }
427
- return linting;
428
- }
429
-
430
- function detectLSPNeeds(deps, projectPath) {
431
- const lsps = [];
432
- if (deps.typescript || fileExists(projectPath, 'tsconfig.json')) lsps.push('typescript');
433
- if (fileExists(projectPath, 'pyproject.toml') || fileExists(projectPath, 'requirements.txt')) lsps.push('python');
434
- if (fileExists(projectPath, 'go.mod')) lsps.push('go');
435
- if (fileExists(projectPath, 'Cargo.toml')) lsps.push('rust');
436
- return lsps;
437
- }
438
-
439
- function detectAllCICD(projectPath) {
440
- const cicd = [];
441
- if (fileExists(projectPath, '.github/workflows')) cicd.push('github-actions');
442
- if (fileExists(projectPath, '.gitlab-ci.yml')) cicd.push('gitlab-ci');
443
- if (fileExists(projectPath, '.circleci')) cicd.push('circleci');
444
- return cicd;
445
- }
446
-
447
- function detectLanguagesExpanded(deps, projectPath) {
448
- const languages = [];
449
- if (deps.typescript || fileExists(projectPath, 'tsconfig.json')) languages.push('typescript');
450
- if (!languages.includes('typescript')) languages.push('javascript');
451
- if (fileExists(projectPath, 'pyproject.toml') || fileExists(projectPath, 'requirements.txt')) languages.push('python');
452
- if (fileExists(projectPath, 'go.mod')) languages.push('go');
453
- if (fileExists(projectPath, 'Cargo.toml')) languages.push('rust');
454
- return languages;
455
- }
456
-
457
- /**
458
- * Detect full tech stack from project files (synchronous, read-only).
459
- * @param {string} projectPath - Project root path
460
- * @returns {{ frameworks: string[], languages: string[], databases: string[], auth: string[], payments: string[], cicd: string[], testing: string[], linting: string[], lsps: string[] }}
461
- */
462
- function detectTechStack(projectPath) {
463
- const pkg = loadPackageJsonSafe(projectPath);
464
- const allDeps = { ...pkg?.dependencies, ...pkg?.devDependencies };
465
- return {
466
- frameworks: detectFrameworks(allDeps),
467
- languages: detectLanguagesExpanded(allDeps, projectPath),
468
- databases: detectDatabases(allDeps),
469
- auth: detectAuthProviders(allDeps),
470
- payments: detectPaymentProviders(allDeps),
471
- cicd: detectAllCICD(projectPath),
472
- testing: detectTestingTools(allDeps),
473
- linting: detectLintingTools(allDeps, projectPath),
474
- lsps: detectLSPNeeds(allDeps, projectPath),
475
- };
476
- }
477
-
478
- module.exports = {
479
- autoDetect,
480
- detectFramework,
481
- detectLanguage,
482
- inferStage,
483
- getGitStats,
484
- detectCICD,
485
- getTestCoverage,
486
- calculateConfidence,
487
- saveContext,
488
- loadContext,
489
- detectInstalledAgents,
490
- detectTechStack,
491
- };
1
+ /**
2
+ * Project Discovery
3
+ *
4
+ * Auto-detects project context (framework, language, stage) from file system.
5
+ */
6
+
7
+ const fs = require('node:fs');
8
+ const path = require('node:path');
9
+ const { execFileSync } = require('node:child_process');
10
+
11
+ async function detectFramework(projectPath) {
12
+ try {
13
+ const packageJsonPath = path.join(projectPath, 'package.json');
14
+ if (!fs.existsSync(packageJsonPath)) return null;
15
+
16
+ const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
17
+ const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
18
+
19
+ if (allDeps['next']) return 'Next.js';
20
+ if (allDeps['react']) return 'React';
21
+ if (allDeps['vue']) return 'Vue.js';
22
+ if (allDeps['express']) return 'Express';
23
+ return null;
24
+ } catch (error) {
25
+ // Return null if package.json doesn't exist or is invalid
26
+ console.warn('Failed to detect framework:', error.message);
27
+ return null;
28
+ }
29
+ }
30
+
31
+ async function detectLanguage(projectPath) {
32
+ try {
33
+ const packageJsonPath = path.join(projectPath, 'package.json');
34
+ if (fs.existsSync(packageJsonPath)) {
35
+ const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
36
+ const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
37
+ if (allDeps['typescript']) return 'typescript';
38
+ }
39
+ return 'javascript';
40
+ } catch (error) {
41
+ // Default to javascript if detection fails
42
+ console.warn('Failed to detect language:', error.message);
43
+ return 'javascript';
44
+ }
45
+ }
46
+
47
+ async function getGitStats(projectPath) {
48
+ try {
49
+ const gitDir = path.join(projectPath, '.git');
50
+ if (!fs.existsSync(gitDir)) {
51
+ return { commits: 0, hasReleases: false };
52
+ }
53
+
54
+ // SECURITY (S4036): Relies on git from PATH - Acceptable for developer CLI tool
55
+ // - This is a developer tool requiring git installation
56
+ // - Commands are hardcoded with no user input (no injection risk)
57
+ // - stdio isolation prevents shell injection
58
+ // - If PATH is compromised to inject malicious git, developer has bigger problems
59
+ // - Cross-platform: absolute paths (/usr/bin/git) would break Windows/macOS variants
60
+ // Use timeout to prevent hanging on slow git operations (Greptile feedback)
61
+ const commitCount = execFileSync('git', ['rev-list', '--count', 'HEAD'], { // NOSONAR S4036 - hardcoded CLI command, no user input, developer tool context
62
+ cwd: projectPath,
63
+ encoding: 'utf8',
64
+ stdio: ['pipe', 'pipe', 'pipe'],
65
+ timeout: 5000 // 5 second timeout
66
+ }).trim();
67
+
68
+ // SECURITY (S4036): Same risk assessment as above - acceptable in developer tool context
69
+ const tags = execFileSync('git', ['tag'], { // NOSONAR S4036 - hardcoded CLI command, no user input, developer tool context
70
+ cwd: projectPath,
71
+ encoding: 'utf8',
72
+ stdio: ['pipe', 'pipe', 'pipe'],
73
+ timeout: 5000 // 5 second timeout
74
+ }).trim();
75
+
76
+ return {
77
+ commits: Number.parseInt(commitCount, 10) || 0,
78
+ hasReleases: tags.split('\n').some(t => t.trim()) // Use .some() instead of .filter().length
79
+ };
80
+ } catch (error) {
81
+ // Return defaults if git commands fail or timeout
82
+ console.warn('Failed to get git stats:', error.message);
83
+ return { commits: 0, hasReleases: false };
84
+ }
85
+ }
86
+
87
+ async function detectCICD(projectPath) {
88
+ const cicdPaths = [
89
+ { path: '.github/workflows', type: 'GitHub Actions' },
90
+ { path: '.gitlab-ci.yml', type: 'GitLab CI' }
91
+ ];
92
+
93
+ for (const { path: ciPath, type } of cicdPaths) {
94
+ if (fs.existsSync(path.join(projectPath, ciPath))) {
95
+ return { exists: true, type };
96
+ }
97
+ }
98
+
99
+ return { exists: false, type: null };
100
+ }
101
+
102
+ async function getTestCoverage(projectPath) {
103
+ try {
104
+ const coveragePath = path.join(projectPath, 'coverage', 'coverage-summary.json');
105
+ if (fs.existsSync(coveragePath)) {
106
+ const coverageData = JSON.parse(await fs.promises.readFile(coveragePath, 'utf8'));
107
+ // Use optional chaining for cleaner, safer access
108
+ return coverageData.total?.lines?.pct || 0;
109
+ }
110
+
111
+ const packageJsonPath = path.join(projectPath, 'package.json');
112
+ if (!fs.existsSync(packageJsonPath)) return 0;
113
+
114
+ const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
115
+ // Use optional chaining
116
+ if (!packageJson.scripts?.test) return 0;
117
+
118
+ return 50;
119
+ } catch (error) {
120
+ // Return 0 if coverage files are missing or invalid
121
+ console.warn('Failed to get test coverage:', error.message);
122
+ return 0;
123
+ }
124
+ }
125
+
126
+ function inferStage(stats) {
127
+ const { commits = 0, hasCICD = false, hasReleases = false, coverage = 0 } = stats;
128
+
129
+ if (commits > 500 && hasCICD && hasReleases && coverage > 80) {
130
+ return 'stable';
131
+ }
132
+
133
+ if (commits < 50 && !hasCICD && coverage < 30) {
134
+ return 'new';
135
+ }
136
+
137
+ if (commits < 20) {
138
+ return 'new';
139
+ }
140
+
141
+ return 'active';
142
+ }
143
+
144
+ function calculateConfidence(context) {
145
+ let score = 0;
146
+ if (context.framework) score += 0.3;
147
+ if (context.language) score += 0.2;
148
+ if (context.commits > 0) score += 0.2;
149
+ if (context.hasCICD) score += 0.15;
150
+ if (context.coverage > 0) score += 0.15;
151
+ return Math.max(score, 0.3);
152
+ }
153
+
154
+ async function autoDetect(projectPath) {
155
+ try {
156
+ const framework = await detectFramework(projectPath);
157
+ const language = await detectLanguage(projectPath);
158
+ const gitStats = await getGitStats(projectPath);
159
+ const cicd = await detectCICD(projectPath);
160
+ const coverage = await getTestCoverage(projectPath);
161
+
162
+ const context = {
163
+ framework,
164
+ language,
165
+ commits: gitStats.commits,
166
+ hasCICD: cicd.exists,
167
+ cicdType: cicd.type,
168
+ hasReleases: gitStats.hasReleases,
169
+ coverage
170
+ };
171
+
172
+ const stage = inferStage(context);
173
+ const confidence = calculateConfidence({ ...context, stage });
174
+
175
+ return { ...context, stage, confidence };
176
+ } catch (error) {
177
+ // Top-level error boundary: return safe defaults if orchestration fails
178
+ console.warn('Failed to auto-detect project context:', error.message);
179
+ return {
180
+ framework: null,
181
+ language: 'javascript',
182
+ commits: 0,
183
+ hasCICD: false,
184
+ cicdType: null,
185
+ hasReleases: false,
186
+ coverage: 0,
187
+ stage: 'new',
188
+ confidence: 0.3
189
+ };
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Save detected context to .forge/context.json
195
+ * Normalized to always expect flat object from autoDetect() (Greptile feedback)
196
+ * @param {Object} context - Flat context object with framework, language, stage, confidence
197
+ * @param {string} projectPath - Project root path
198
+ */
199
+ async function saveContext(context, projectPath) {
200
+ const forgeDir = path.join(projectPath, '.forge');
201
+ const contextPath = path.join(forgeDir, 'context.json');
202
+
203
+ await fs.promises.mkdir(forgeDir, { recursive: true });
204
+
205
+ // Always expect flat shape from autoDetect(), build nested structure internally
206
+ const data = {
207
+ auto_detected: {
208
+ framework: context.framework,
209
+ language: context.language,
210
+ stage: context.stage,
211
+ confidence: context.confidence,
212
+ // Include optional fields if present
213
+ ...(context.commits !== undefined && { commits: context.commits }),
214
+ ...(context.hasCICD !== undefined && { hasCICD: context.hasCICD }),
215
+ ...(context.hasReleases !== undefined && { hasReleases: context.hasReleases }),
216
+ ...(context.coverage !== undefined && { coverage: context.coverage })
217
+ },
218
+ user_provided: {},
219
+ last_updated: new Date().toISOString()
220
+ };
221
+
222
+ await fs.promises.writeFile(contextPath, JSON.stringify(data, null, 2), 'utf8');
223
+ }
224
+
225
+ async function loadContext(projectPath) {
226
+ try {
227
+ const contextPath = path.join(projectPath, '.forge', 'context.json');
228
+ if (!fs.existsSync(contextPath)) return null;
229
+
230
+ const data = await fs.promises.readFile(contextPath, 'utf8');
231
+ return JSON.parse(data);
232
+ } catch (error) {
233
+ // Return null if context file doesn't exist or is invalid
234
+ console.warn('Failed to load context:', error.message);
235
+ return null;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Detect which AI coding agents are installed/configured in the project
241
+ * @param {string} projectPath - Path to the project root
242
+ * @returns {Promise<string[]>} - Array of detected agent identifiers
243
+ */
244
+ async function detectInstalledAgents(projectPath) {
245
+ const detectedAgents = [];
246
+
247
+ try {
248
+ // Define detection patterns for each agent
249
+ const agentDetectors = [
250
+ {
251
+ name: 'claude',
252
+ checks: [
253
+ // .claude directory (primary indicator)
254
+ async () => {
255
+ const claudeDir = path.join(projectPath, '.claude');
256
+ return fs.existsSync(claudeDir) && (await fs.promises.stat(claudeDir)).isDirectory();
257
+ },
258
+ // CLAUDE.md file (legacy indicator)
259
+ async () => {
260
+ const claudeMd = path.join(projectPath, 'CLAUDE.md');
261
+ return fs.existsSync(claudeMd);
262
+ }
263
+ ]
264
+ },
265
+ {
266
+ name: 'copilot',
267
+ checks: [
268
+ // .github/copilot-instructions.md
269
+ async () => {
270
+ const copilotFile = path.join(projectPath, '.github', 'copilot-instructions.md');
271
+ return fs.existsSync(copilotFile);
272
+ }
273
+ ]
274
+ },
275
+ {
276
+ name: 'cursor',
277
+ checks: [
278
+ // .cursor directory
279
+ async () => {
280
+ const cursorDir = path.join(projectPath, '.cursor');
281
+ return fs.existsSync(cursorDir) && (await fs.promises.stat(cursorDir)).isDirectory();
282
+ }
283
+ ]
284
+ },
285
+ {
286
+ name: 'kilo',
287
+ checks: [
288
+ // .kilo.md file
289
+ async () => {
290
+ const kiloMd = path.join(projectPath, '.kilo.md');
291
+ return fs.existsSync(kiloMd);
292
+ }
293
+ ]
294
+ },
295
+ {
296
+ name: 'opencode',
297
+ checks: [
298
+ // opencode.json file
299
+ async () => {
300
+ const opencodeJson = path.join(projectPath, 'opencode.json');
301
+ return fs.existsSync(opencodeJson);
302
+ }
303
+ ]
304
+ }
305
+ ];
306
+
307
+ // Check each agent
308
+ for (const detector of agentDetectors) {
309
+ // Check if any of the detection patterns match
310
+ for (const check of detector.checks) {
311
+ try {
312
+ const detected = await check();
313
+ if (detected) {
314
+ detectedAgents.push(detector.name);
315
+ break; // Agent detected, no need to check other patterns
316
+ }
317
+ } catch (_error) {
318
+ // Ignore errors for individual checks (e.g., permission issues)
319
+ continue;
320
+ }
321
+ }
322
+ }
323
+
324
+ return detectedAgents;
325
+ } catch (error) {
326
+ // Return empty array if detection fails entirely
327
+ console.warn('Failed to detect installed agents:', error.message);
328
+ return [];
329
+ }
330
+ }
331
+
332
+ // ── Tech Stack Detection (synchronous, read-only) ──
333
+
334
+ function loadPackageJsonSafe(projectPath) {
335
+ try {
336
+ const pkgPath = path.join(projectPath, 'package.json');
337
+ if (!fs.existsSync(pkgPath)) return null;
338
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
339
+ } catch {
340
+ return null;
341
+ }
342
+ }
343
+
344
+ function fileExists(projectPath, fileName) {
345
+ return fs.existsSync(path.join(projectPath, fileName));
346
+ }
347
+
348
+ function detectFrameworks(deps) {
349
+ const frameworks = [];
350
+ const map = {
351
+ next: 'nextjs', react: 'react', vue: 'vue', '@angular/core': 'angular',
352
+ svelte: 'svelte', astro: 'astro', '@remix-run/node': 'remix',
353
+ nuxt: 'nuxt', express: 'express', fastify: 'fastify', '@nestjs/core': 'nestjs',
354
+ };
355
+ for (const [dep, name] of Object.entries(map)) {
356
+ if (deps[dep]) frameworks.push(name);
357
+ }
358
+ return frameworks;
359
+ }
360
+
361
+ function detectDatabases(deps) {
362
+ const dbs = [];
363
+ const map = {
364
+ '@supabase/supabase-js': 'supabase', '@neondatabase/serverless': 'neon',
365
+ convex: 'convex', '@prisma/client': 'prisma', drizzle: 'drizzle',
366
+ 'drizzle-orm': 'drizzle', mongodb: 'mongodb', mongoose: 'mongodb', pg: 'postgresql',
367
+ };
368
+ for (const [dep, name] of Object.entries(map)) {
369
+ if (deps[dep] && !dbs.includes(name)) dbs.push(name);
370
+ }
371
+ return dbs;
372
+ }
373
+
374
+ function detectAuthProviders(deps) {
375
+ const auth = [];
376
+ const map = {
377
+ '@clerk/nextjs': 'clerk', '@clerk/clerk-react': 'clerk',
378
+ 'next-auth': 'authjs', '@auth/core': 'authjs',
379
+ firebase: 'firebase-auth', '@firebase/auth': 'firebase-auth',
380
+ };
381
+ for (const [dep, name] of Object.entries(map)) {
382
+ if (deps[dep] && !auth.includes(name)) auth.push(name);
383
+ }
384
+ // Supabase auth detected via supabase-js
385
+ if (deps['@supabase/supabase-js'] && !auth.includes('supabase-auth')) {
386
+ auth.push('supabase-auth');
387
+ }
388
+ return auth;
389
+ }
390
+
391
+ function detectPaymentProviders(deps) {
392
+ const payments = [];
393
+ const map = {
394
+ stripe: 'stripe', '@paddle/paddle-js': 'paddle',
395
+ '@lemonsqueezy/lemonsqueezy.js': 'lemonsqueezy',
396
+ };
397
+ for (const [dep, name] of Object.entries(map)) {
398
+ if (deps[dep]) payments.push(name);
399
+ }
400
+ return payments;
401
+ }
402
+
403
+ function detectTestingTools(deps) {
404
+ const testing = [];
405
+ const map = {
406
+ vitest: 'vitest', jest: 'jest', '@playwright/test': 'playwright',
407
+ cypress: 'cypress', mocha: 'mocha',
408
+ };
409
+ for (const [dep, name] of Object.entries(map)) {
410
+ if (deps[dep]) testing.push(name);
411
+ }
412
+ return testing;
413
+ }
414
+
415
+ function detectLintingTools(deps, projectPath) {
416
+ const linting = [];
417
+ if (deps.eslint || fileExists(projectPath, 'eslint.config.js') || fileExists(projectPath, '.eslintrc.json')) {
418
+ linting.push('eslint');
419
+ }
420
+ if (fileExists(projectPath, 'biome.json') || deps['@biomejs/biome']) {
421
+ linting.push('biome');
422
+ }
423
+ if (deps.oxlint) linting.push('oxlint');
424
+ if (deps.prettier || fileExists(projectPath, '.prettierrc') || fileExists(projectPath, '.prettierrc.json')) {
425
+ linting.push('prettier');
426
+ }
427
+ return linting;
428
+ }
429
+
430
+ function detectLSPNeeds(deps, projectPath) {
431
+ const lsps = [];
432
+ if (deps.typescript || fileExists(projectPath, 'tsconfig.json')) lsps.push('typescript');
433
+ if (fileExists(projectPath, 'pyproject.toml') || fileExists(projectPath, 'requirements.txt')) lsps.push('python');
434
+ if (fileExists(projectPath, 'go.mod')) lsps.push('go');
435
+ if (fileExists(projectPath, 'Cargo.toml')) lsps.push('rust');
436
+ return lsps;
437
+ }
438
+
439
+ function detectAllCICD(projectPath) {
440
+ const cicd = [];
441
+ if (fileExists(projectPath, '.github/workflows')) cicd.push('github-actions');
442
+ if (fileExists(projectPath, '.gitlab-ci.yml')) cicd.push('gitlab-ci');
443
+ if (fileExists(projectPath, '.circleci')) cicd.push('circleci');
444
+ return cicd;
445
+ }
446
+
447
+ function detectLanguagesExpanded(deps, projectPath) {
448
+ const languages = [];
449
+ if (deps.typescript || fileExists(projectPath, 'tsconfig.json')) languages.push('typescript');
450
+ if (!languages.includes('typescript')) languages.push('javascript');
451
+ if (fileExists(projectPath, 'pyproject.toml') || fileExists(projectPath, 'requirements.txt')) languages.push('python');
452
+ if (fileExists(projectPath, 'go.mod')) languages.push('go');
453
+ if (fileExists(projectPath, 'Cargo.toml')) languages.push('rust');
454
+ return languages;
455
+ }
456
+
457
+ /**
458
+ * Detect full tech stack from project files (synchronous, read-only).
459
+ * @param {string} projectPath - Project root path
460
+ * @returns {{ frameworks: string[], languages: string[], databases: string[], auth: string[], payments: string[], cicd: string[], testing: string[], linting: string[], lsps: string[] }}
461
+ */
462
+ function detectTechStack(projectPath) {
463
+ const pkg = loadPackageJsonSafe(projectPath);
464
+ const allDeps = { ...pkg?.dependencies, ...pkg?.devDependencies };
465
+ return {
466
+ frameworks: detectFrameworks(allDeps),
467
+ languages: detectLanguagesExpanded(allDeps, projectPath),
468
+ databases: detectDatabases(allDeps),
469
+ auth: detectAuthProviders(allDeps),
470
+ payments: detectPaymentProviders(allDeps),
471
+ cicd: detectAllCICD(projectPath),
472
+ testing: detectTestingTools(allDeps),
473
+ linting: detectLintingTools(allDeps, projectPath),
474
+ lsps: detectLSPNeeds(allDeps, projectPath),
475
+ };
476
+ }
477
+
478
+ module.exports = {
479
+ autoDetect,
480
+ detectFramework,
481
+ detectLanguage,
482
+ inferStage,
483
+ getGitStats,
484
+ detectCICD,
485
+ getTestCoverage,
486
+ calculateConfidence,
487
+ saveContext,
488
+ loadContext,
489
+ detectInstalledAgents,
490
+ detectTechStack,
491
+ };