forge-workflow 0.0.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.
Files changed (105) hide show
  1. package/.claude/commands/dev.md +314 -0
  2. package/.claude/commands/plan.md +389 -0
  3. package/.claude/commands/premerge.md +179 -0
  4. package/.claude/commands/research.md +42 -0
  5. package/.claude/commands/review.md +442 -0
  6. package/.claude/commands/rollback.md +721 -0
  7. package/.claude/commands/ship.md +134 -0
  8. package/.claude/commands/sonarcloud.md +152 -0
  9. package/.claude/commands/status.md +77 -0
  10. package/.claude/commands/validate.md +237 -0
  11. package/.claude/commands/verify.md +221 -0
  12. package/.claude/rules/greptile-review-process.md +285 -0
  13. package/.claude/rules/workflow.md +105 -0
  14. package/.claude/scripts/greptile-resolve.sh +526 -0
  15. package/.claude/scripts/load-env.sh +32 -0
  16. package/.forge/hooks/check-tdd.js +240 -0
  17. package/.github/PLUGIN_TEMPLATE.json +32 -0
  18. package/.mcp.json.example +12 -0
  19. package/AGENTS.md +169 -0
  20. package/CLAUDE.md +99 -0
  21. package/LICENSE +21 -0
  22. package/README.md +414 -0
  23. package/bin/forge-cmd.js +313 -0
  24. package/bin/forge-validate.js +303 -0
  25. package/bin/forge.js +4228 -0
  26. package/docs/AGENT_INSTALL_PROMPT.md +342 -0
  27. package/docs/ENHANCED_ONBOARDING.md +602 -0
  28. package/docs/EXAMPLES.md +482 -0
  29. package/docs/GREPTILE_SETUP.md +400 -0
  30. package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
  31. package/docs/ROADMAP.md +359 -0
  32. package/docs/SETUP.md +632 -0
  33. package/docs/TOOLCHAIN.md +849 -0
  34. package/docs/VALIDATION.md +363 -0
  35. package/docs/WORKFLOW.md +400 -0
  36. package/docs/planning/PROGRESS.md +396 -0
  37. package/docs/plans/.gitkeep +0 -0
  38. package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
  39. package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
  40. package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
  41. package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
  42. package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
  43. package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
  44. package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
  45. package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
  46. package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
  47. package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
  48. package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
  49. package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
  50. package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
  51. package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
  52. package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
  53. package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
  54. package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
  55. package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
  56. package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
  57. package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
  58. package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
  59. package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
  60. package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
  61. package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
  62. package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
  63. package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
  64. package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
  65. package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
  66. package/docs/research/TEMPLATE.md +292 -0
  67. package/docs/research/advanced-testing.md +297 -0
  68. package/docs/research/agent-permissions.md +167 -0
  69. package/docs/research/dependency-chain.md +328 -0
  70. package/docs/research/forge-workflow-v2.md +550 -0
  71. package/docs/research/plugin-architecture.md +772 -0
  72. package/docs/research/pr4-cli-automation.md +326 -0
  73. package/docs/research/premerge-verify-restructure.md +205 -0
  74. package/docs/research/skills-restructure.md +508 -0
  75. package/docs/research/sonarcloud-perfection-plan.md +166 -0
  76. package/docs/research/sonarcloud-quality-gate.md +184 -0
  77. package/docs/research/superpowers-integration.md +403 -0
  78. package/docs/research/superpowers.md +319 -0
  79. package/docs/research/test-environment.md +519 -0
  80. package/install.sh +1062 -0
  81. package/lefthook.yml +39 -0
  82. package/lib/agents/README.md +198 -0
  83. package/lib/agents/claude.plugin.json +28 -0
  84. package/lib/agents/cline.plugin.json +22 -0
  85. package/lib/agents/codex.plugin.json +19 -0
  86. package/lib/agents/copilot.plugin.json +24 -0
  87. package/lib/agents/cursor.plugin.json +25 -0
  88. package/lib/agents/kilocode.plugin.json +22 -0
  89. package/lib/agents/opencode.plugin.json +20 -0
  90. package/lib/agents/roo.plugin.json +23 -0
  91. package/lib/agents-config.js +2112 -0
  92. package/lib/commands/dev.js +513 -0
  93. package/lib/commands/plan.js +696 -0
  94. package/lib/commands/recommend.js +119 -0
  95. package/lib/commands/ship.js +377 -0
  96. package/lib/commands/status.js +378 -0
  97. package/lib/commands/validate.js +602 -0
  98. package/lib/context-merge.js +359 -0
  99. package/lib/plugin-catalog.js +360 -0
  100. package/lib/plugin-manager.js +166 -0
  101. package/lib/plugin-recommender.js +141 -0
  102. package/lib/project-discovery.js +491 -0
  103. package/lib/setup.js +118 -0
  104. package/lib/workflow-profiles.js +203 -0
  105. package/package.json +115 -0
@@ -0,0 +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
+ };
package/lib/setup.js ADDED
@@ -0,0 +1,118 @@
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+
4
+ /**
5
+ * Save setup state to .forge/setup-state.json
6
+ * @param {string} projectPath - Path to the project root
7
+ * @param {Object} state - Setup state object
8
+ * @param {string} state.version - Forge version
9
+ * @param {string[]} state.completed_steps - List of completed steps
10
+ * @param {string[]} state.pending_steps - List of pending steps
11
+ * @param {string} [state.last_run] - ISO timestamp of last run
12
+ * @returns {Promise<void>}
13
+ */
14
+ async function saveSetupState(projectPath, state) {
15
+ const forgeDir = path.join(projectPath, '.forge');
16
+ const setupStatePath = path.join(forgeDir, 'setup-state.json');
17
+
18
+ // Ensure .forge directory exists
19
+ await fs.promises.mkdir(forgeDir, { recursive: true });
20
+
21
+ // Add last_run timestamp if not provided
22
+ if (!state.last_run) {
23
+ state.last_run = new Date().toISOString();
24
+ }
25
+
26
+ // Write state as JSON
27
+ await fs.promises.writeFile(setupStatePath, JSON.stringify(state, null, 2), 'utf-8');
28
+ }
29
+
30
+ /**
31
+ * Load setup state from .forge/setup-state.json
32
+ * @param {string} projectPath - Path to the project root
33
+ * @returns {Promise<Object|null>} Setup state object, or null if not found or invalid
34
+ */
35
+ async function loadSetupState(projectPath) {
36
+ const setupStatePath = path.join(projectPath, '.forge', 'setup-state.json');
37
+
38
+ try {
39
+ const content = await fs.promises.readFile(setupStatePath, 'utf-8');
40
+ return JSON.parse(content);
41
+ } catch (_error) {
42
+ // File doesn't exist or invalid JSON
43
+ return null;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Check if setup is complete (no pending steps)
49
+ * @param {string} projectPath - Path to the project root
50
+ * @returns {Promise<boolean>} True if setup complete, false otherwise
51
+ */
52
+ async function isSetupComplete(projectPath) {
53
+ const state = await loadSetupState(projectPath);
54
+
55
+ if (!state) {
56
+ return false;
57
+ }
58
+
59
+ // Setup is complete if pending_steps is empty
60
+ return state.pending_steps.length === 0;
61
+ }
62
+
63
+ /**
64
+ * Get the next pending step
65
+ * @param {string} projectPath - Path to the project root
66
+ * @returns {Promise<string|null>} Next step name, or null if none
67
+ */
68
+ async function getNextStep(projectPath) {
69
+ const state = await loadSetupState(projectPath);
70
+
71
+ if (!state || !state.pending_steps || state.pending_steps.length === 0) {
72
+ return null;
73
+ }
74
+
75
+ // Return first pending step
76
+ return state.pending_steps[0];
77
+ }
78
+
79
+ /**
80
+ * Mark a step as complete (move from pending to completed)
81
+ * @param {string} projectPath - Path to the project root
82
+ * @param {string} stepName - Name of the step to mark complete
83
+ * @returns {Promise<void>}
84
+ */
85
+ async function markStepComplete(projectPath, stepName) {
86
+ let state = await loadSetupState(projectPath);
87
+
88
+ // If no state exists, create initial state
89
+ if (!state) {
90
+ state = {
91
+ version: '1.6.0',
92
+ completed_steps: [],
93
+ pending_steps: []
94
+ };
95
+ }
96
+
97
+ // Remove from pending_steps if present
98
+ state.pending_steps = state.pending_steps.filter(step => step !== stepName);
99
+
100
+ // Add to completed_steps if not already there
101
+ if (!state.completed_steps.includes(stepName)) {
102
+ state.completed_steps.push(stepName);
103
+ }
104
+
105
+ // Update last_run timestamp
106
+ state.last_run = new Date().toISOString();
107
+
108
+ // Save updated state
109
+ await saveSetupState(projectPath, state);
110
+ }
111
+
112
+ module.exports = {
113
+ saveSetupState,
114
+ loadSetupState,
115
+ isSetupComplete,
116
+ getNextStep,
117
+ markStepComplete
118
+ };