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.
- package/.claude/commands/dev.md +314 -0
- package/.claude/commands/plan.md +389 -0
- package/.claude/commands/premerge.md +179 -0
- package/.claude/commands/research.md +42 -0
- package/.claude/commands/review.md +442 -0
- package/.claude/commands/rollback.md +721 -0
- package/.claude/commands/ship.md +134 -0
- package/.claude/commands/sonarcloud.md +152 -0
- package/.claude/commands/status.md +77 -0
- package/.claude/commands/validate.md +237 -0
- package/.claude/commands/verify.md +221 -0
- package/.claude/rules/greptile-review-process.md +285 -0
- package/.claude/rules/workflow.md +105 -0
- package/.claude/scripts/greptile-resolve.sh +526 -0
- package/.claude/scripts/load-env.sh +32 -0
- package/.forge/hooks/check-tdd.js +240 -0
- package/.github/PLUGIN_TEMPLATE.json +32 -0
- package/.mcp.json.example +12 -0
- package/AGENTS.md +169 -0
- package/CLAUDE.md +99 -0
- package/LICENSE +21 -0
- package/README.md +414 -0
- package/bin/forge-cmd.js +313 -0
- package/bin/forge-validate.js +303 -0
- package/bin/forge.js +4228 -0
- package/docs/AGENT_INSTALL_PROMPT.md +342 -0
- package/docs/ENHANCED_ONBOARDING.md +602 -0
- package/docs/EXAMPLES.md +482 -0
- package/docs/GREPTILE_SETUP.md +400 -0
- package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
- package/docs/ROADMAP.md +359 -0
- package/docs/SETUP.md +632 -0
- package/docs/TOOLCHAIN.md +849 -0
- package/docs/VALIDATION.md +363 -0
- package/docs/WORKFLOW.md +400 -0
- package/docs/planning/PROGRESS.md +396 -0
- package/docs/plans/.gitkeep +0 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
- package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
- package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
- package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
- package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
- package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
- package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
- package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
- package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
- package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
- package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
- package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
- package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
- package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
- package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
- package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
- package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
- package/docs/research/TEMPLATE.md +292 -0
- package/docs/research/advanced-testing.md +297 -0
- package/docs/research/agent-permissions.md +167 -0
- package/docs/research/dependency-chain.md +328 -0
- package/docs/research/forge-workflow-v2.md +550 -0
- package/docs/research/plugin-architecture.md +772 -0
- package/docs/research/pr4-cli-automation.md +326 -0
- package/docs/research/premerge-verify-restructure.md +205 -0
- package/docs/research/skills-restructure.md +508 -0
- package/docs/research/sonarcloud-perfection-plan.md +166 -0
- package/docs/research/sonarcloud-quality-gate.md +184 -0
- package/docs/research/superpowers-integration.md +403 -0
- package/docs/research/superpowers.md +319 -0
- package/docs/research/test-environment.md +519 -0
- package/install.sh +1062 -0
- package/lefthook.yml +39 -0
- package/lib/agents/README.md +198 -0
- package/lib/agents/claude.plugin.json +28 -0
- package/lib/agents/cline.plugin.json +22 -0
- package/lib/agents/codex.plugin.json +19 -0
- package/lib/agents/copilot.plugin.json +24 -0
- package/lib/agents/cursor.plugin.json +25 -0
- package/lib/agents/kilocode.plugin.json +22 -0
- package/lib/agents/opencode.plugin.json +20 -0
- package/lib/agents/roo.plugin.json +23 -0
- package/lib/agents-config.js +2112 -0
- package/lib/commands/dev.js +513 -0
- package/lib/commands/plan.js +696 -0
- package/lib/commands/recommend.js +119 -0
- package/lib/commands/ship.js +377 -0
- package/lib/commands/status.js +378 -0
- package/lib/commands/validate.js +602 -0
- package/lib/context-merge.js +359 -0
- package/lib/plugin-catalog.js +360 -0
- package/lib/plugin-manager.js +166 -0
- package/lib/plugin-recommender.js +141 -0
- package/lib/project-discovery.js +491 -0
- package/lib/setup.js +118 -0
- package/lib/workflow-profiles.js +203 -0
- package/package.json +115 -0
|
@@ -0,0 +1,2112 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate universal AGENTS.md file that works with all supported AI agents
|
|
6
|
+
* @param {string} projectPath - Path to the project root
|
|
7
|
+
* @returns {Promise<void>}
|
|
8
|
+
*/
|
|
9
|
+
async function generateAgentsMd(projectPath, options = {}) {
|
|
10
|
+
const agentsMdPath = path.join(projectPath, 'AGENTS.md');
|
|
11
|
+
|
|
12
|
+
// Check overwrite protection
|
|
13
|
+
if (!options.overwrite && fs.existsSync(agentsMdPath)) {
|
|
14
|
+
// File exists and overwrite is false - skip
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Detect project metadata
|
|
19
|
+
const projectMeta = options.projectMeta || await detectProjectMetadata(projectPath);
|
|
20
|
+
|
|
21
|
+
// Generate AGENTS.md content
|
|
22
|
+
const content = generateAgentsMdContent(projectMeta);
|
|
23
|
+
|
|
24
|
+
// Write to file
|
|
25
|
+
await fs.promises.writeFile(agentsMdPath, content, 'utf-8');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Detect project metadata (language, framework, scripts)
|
|
30
|
+
* @param {string} projectPath - Path to the project root
|
|
31
|
+
* @returns {Promise<Object>}
|
|
32
|
+
*/
|
|
33
|
+
async function detectProjectMetadata(projectPath) {
|
|
34
|
+
const meta = {
|
|
35
|
+
name: 'project',
|
|
36
|
+
language: null,
|
|
37
|
+
framework: null,
|
|
38
|
+
testCommand: 'npm test',
|
|
39
|
+
buildCommand: 'npm run build'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Try to read package.json
|
|
43
|
+
try {
|
|
44
|
+
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
45
|
+
const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf-8'));
|
|
46
|
+
|
|
47
|
+
meta.name = packageJson.name || 'project';
|
|
48
|
+
|
|
49
|
+
// Detect TypeScript
|
|
50
|
+
if (packageJson.dependencies?.typescript || packageJson.devDependencies?.typescript) {
|
|
51
|
+
meta.language = 'TypeScript';
|
|
52
|
+
meta.hasTypeScript = true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Detect test command
|
|
56
|
+
if (packageJson.scripts?.test) {
|
|
57
|
+
meta.testCommand = packageJson.scripts.test;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Detect build command
|
|
61
|
+
if (packageJson.scripts?.build) {
|
|
62
|
+
meta.buildCommand = packageJson.scripts.build;
|
|
63
|
+
}
|
|
64
|
+
} catch (_error) {
|
|
65
|
+
// package.json doesn't exist or is invalid, use defaults
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return meta;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Generate AGENTS.md content
|
|
73
|
+
* @param {Object} meta - Project metadata
|
|
74
|
+
* @returns {string} - AGENTS.md content
|
|
75
|
+
*/
|
|
76
|
+
function generateAgentsMdContent(meta) {
|
|
77
|
+
return `# Forge Workflow Framework
|
|
78
|
+
|
|
79
|
+
This project uses the **Forge 7-Stage TDD Workflow** for development.
|
|
80
|
+
|
|
81
|
+
## Supported AI Agents
|
|
82
|
+
|
|
83
|
+
This workflow works with all major AI coding agents:
|
|
84
|
+
- **Claude Code** - Native custom slash commands, skills
|
|
85
|
+
- **GitHub Copilot** - Enterprise support, multi-editor, MCP
|
|
86
|
+
- **Kilo Code** - Auto failure recovery, managed indexing
|
|
87
|
+
- **Cursor** - IDE-integrated, native Plan/Ask/Debug modes
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
\`\`\`bash
|
|
92
|
+
bun install # Install dependencies
|
|
93
|
+
${meta.testCommand} # Run tests
|
|
94
|
+
${meta.buildCommand} # Build project
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
## Forge 7-Stage TDD Workflow
|
|
98
|
+
|
|
99
|
+
### Utility: /status
|
|
100
|
+
Check current context and active work
|
|
101
|
+
- Review git status and recent commits
|
|
102
|
+
- Check Beads issues (if installed) for active work
|
|
103
|
+
- Identify current workflow stage
|
|
104
|
+
|
|
105
|
+
### Stage 1: /plan
|
|
106
|
+
Create implementation plan
|
|
107
|
+
- Research with web search (parallel-ai MCP recommended)
|
|
108
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
109
|
+
- Include decision rationale and security considerations
|
|
110
|
+
- Generate plan, create Beads issue, break into TDD cycles
|
|
111
|
+
|
|
112
|
+
### Stage 2: /dev
|
|
113
|
+
TDD development (RED-GREEN-REFACTOR)
|
|
114
|
+
- **RED**: Write failing test FIRST
|
|
115
|
+
- **GREEN**: Implement minimal code to pass
|
|
116
|
+
- **REFACTOR**: Clean up and optimize
|
|
117
|
+
- Commit after each cycle
|
|
118
|
+
- Push regularly to remote
|
|
119
|
+
|
|
120
|
+
### Stage 3: /validate
|
|
121
|
+
Validation and quality gates
|
|
122
|
+
- Type checking${meta.language === 'TypeScript' ? ' (TypeScript strict mode)' : ''}
|
|
123
|
+
- Linting (ESLint)
|
|
124
|
+
- Security scanning (npm audit, OWASP checks)
|
|
125
|
+
- Test suite (all tests must pass)
|
|
126
|
+
- Code coverage verification
|
|
127
|
+
|
|
128
|
+
### Stage 4: /ship
|
|
129
|
+
Create pull request
|
|
130
|
+
- Generate PR body with context
|
|
131
|
+
- Reference Beads issues
|
|
132
|
+
- Include test coverage metrics
|
|
133
|
+
- Link to research and plan documents
|
|
134
|
+
|
|
135
|
+
### Stage 5: /review
|
|
136
|
+
Address ALL PR feedback
|
|
137
|
+
- GitHub Actions failures
|
|
138
|
+
- Code review comments
|
|
139
|
+
- AI review tools (Greptile, CodeRabbit if configured)
|
|
140
|
+
- Security scan results
|
|
141
|
+
- Resolve all threads before merge
|
|
142
|
+
|
|
143
|
+
### Stage 6: /premerge
|
|
144
|
+
Merge and cleanup
|
|
145
|
+
- Update documentation
|
|
146
|
+
- Merge pull request (squash commits)
|
|
147
|
+
- Delete feature branch
|
|
148
|
+
- Archive completed work
|
|
149
|
+
- Close Beads issues
|
|
150
|
+
|
|
151
|
+
### Stage 7: /verify
|
|
152
|
+
Final documentation cross-check
|
|
153
|
+
- Verify all docs updated correctly
|
|
154
|
+
- Check for broken links
|
|
155
|
+
- Validate code examples
|
|
156
|
+
- Ensure consistency across documentation
|
|
157
|
+
|
|
158
|
+
## Core Principles
|
|
159
|
+
|
|
160
|
+
### TDD-First Development
|
|
161
|
+
- Tests written UPFRONT in RED-GREEN-REFACTOR cycles
|
|
162
|
+
- No implementation without failing test first
|
|
163
|
+
- Commit after each GREEN cycle
|
|
164
|
+
- Maintain high code coverage (80%+)
|
|
165
|
+
|
|
166
|
+
### Research-First Approach
|
|
167
|
+
- All features start with comprehensive research
|
|
168
|
+
- Use web search for best practices and security analysis
|
|
169
|
+
- Document findings before implementation
|
|
170
|
+
- Include OWASP Top 10 analysis for security-critical features
|
|
171
|
+
|
|
172
|
+
### Security Built-In
|
|
173
|
+
- OWASP Top 10 analysis for every new feature
|
|
174
|
+
- Security test scenarios identified upfront
|
|
175
|
+
- Automated scans + manual review
|
|
176
|
+
- Input validation and sanitization
|
|
177
|
+
|
|
178
|
+
### Documentation Progressive
|
|
179
|
+
- Updated at relevant stages (not deferred to end)
|
|
180
|
+
- Cross-checked at /verify stage
|
|
181
|
+
- Never accumulate documentation debt
|
|
182
|
+
- Keep README, docs/, and inline comments synchronized
|
|
183
|
+
|
|
184
|
+
## Tech Stack
|
|
185
|
+
|
|
186
|
+
${meta.language ? `- **Language**: ${meta.language}` : ''}
|
|
187
|
+
- **Package Manager**: Bun (recommended)
|
|
188
|
+
- **Testing**: TDD-first with high coverage
|
|
189
|
+
- **Security**: OWASP Top 10 compliance
|
|
190
|
+
- **Version Control**: Git with conventional commits
|
|
191
|
+
|
|
192
|
+
## MCP Servers (Model Context Protocol)
|
|
193
|
+
|
|
194
|
+
If your agent supports MCP, configure these servers for enhanced capabilities:
|
|
195
|
+
|
|
196
|
+
- **parallel-ai**: Web research and data enrichment
|
|
197
|
+
- **context7**: Up-to-date library documentation
|
|
198
|
+
- **github**: Repository integration (often built-in)
|
|
199
|
+
|
|
200
|
+
Configuration: \`.mcp.json\` or agent-specific config files
|
|
201
|
+
|
|
202
|
+
## Issue Tracking
|
|
203
|
+
|
|
204
|
+
Use **Beads** for persistent tracking across sessions:
|
|
205
|
+
|
|
206
|
+
\`\`\`bash
|
|
207
|
+
bd create "Feature name" # Create issue
|
|
208
|
+
bd update <id> --status in_progress # Claim work
|
|
209
|
+
bd update <id> --comment "Progress" # Add notes
|
|
210
|
+
bd close <id> # Complete
|
|
211
|
+
bd sync # Sync with git
|
|
212
|
+
\`\`\`
|
|
213
|
+
|
|
214
|
+
## Git Workflow
|
|
215
|
+
|
|
216
|
+
**Branch naming**:
|
|
217
|
+
- \`feat/<feature-slug>\` - New features
|
|
218
|
+
- \`fix/<bug-slug>\` - Bug fixes
|
|
219
|
+
- \`docs/<doc-slug>\` - Documentation updates
|
|
220
|
+
|
|
221
|
+
**Commit pattern**:
|
|
222
|
+
\`\`\`bash
|
|
223
|
+
git commit -m "test: add validation tests" # RED
|
|
224
|
+
git commit -m "feat: implement validation" # GREEN
|
|
225
|
+
git commit -m "refactor: extract helpers" # REFACTOR
|
|
226
|
+
\`\`\`
|
|
227
|
+
|
|
228
|
+
**Pre-commit hooks** (automatic via Lefthook):
|
|
229
|
+
- TDD enforcement (source files must have tests)
|
|
230
|
+
- Interactive prompts (option to unstage, continue, or abort)
|
|
231
|
+
|
|
232
|
+
**Pre-push hooks** (automatic):
|
|
233
|
+
- Branch protection (blocks direct push to main/master)
|
|
234
|
+
- ESLint check (blocks on errors)
|
|
235
|
+
- Test suite (all tests must pass)
|
|
236
|
+
|
|
237
|
+
## Agent-Specific Enhancements
|
|
238
|
+
|
|
239
|
+
While this universal AGENTS.md works with all agents, you can optionally enable agent-specific enhancements:
|
|
240
|
+
|
|
241
|
+
- **GitHub Copilot**: \`.github/copilot-instructions.md\` + path-specific instructions
|
|
242
|
+
- **Cursor**: \`.cursor/rules/*.mdc\` + native modes
|
|
243
|
+
- **OpenCode**: \`opencode.json\` + custom agents
|
|
244
|
+
- **Kilo**: \`.kilo.md\` + built-in commands
|
|
245
|
+
|
|
246
|
+
Generate with: \`bunx forge setup --agent=<name>\`
|
|
247
|
+
|
|
248
|
+
## Support
|
|
249
|
+
|
|
250
|
+
- **Documentation**: \`docs/\` directory
|
|
251
|
+
- **Workflow Guide**: \`docs/WORKFLOW.md\`
|
|
252
|
+
- **Architecture**: \`docs/ARCHITECTURE.md\` (if it exists)
|
|
253
|
+
- **Configuration**: \`docs/CONFIGURATION.md\` (if it exists)
|
|
254
|
+
|
|
255
|
+
For questions or issues with Forge workflow, see project documentation or GitHub repository.
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Generate GitHub Copilot configuration files
|
|
261
|
+
* @param {string} projectPath - Path to the project root
|
|
262
|
+
* @param {Object} options - Generation options
|
|
263
|
+
* @param {boolean} options.overwrite - Whether to overwrite existing files (default: false)
|
|
264
|
+
* @returns {Promise<void>}
|
|
265
|
+
*/
|
|
266
|
+
async function generateCopilotConfig(projectPath, options = {}) {
|
|
267
|
+
const { overwrite = false } = options;
|
|
268
|
+
|
|
269
|
+
// Detect project metadata
|
|
270
|
+
const projectMeta = await detectProjectMetadata(projectPath);
|
|
271
|
+
|
|
272
|
+
// Create .github directory structure
|
|
273
|
+
const githubDir = path.join(projectPath, '.github');
|
|
274
|
+
const instructionsDir = path.join(githubDir, 'instructions');
|
|
275
|
+
const promptsDir = path.join(githubDir, 'prompts');
|
|
276
|
+
|
|
277
|
+
await fs.promises.mkdir(instructionsDir, { recursive: true });
|
|
278
|
+
await fs.promises.mkdir(promptsDir, { recursive: true });
|
|
279
|
+
|
|
280
|
+
// Helper to write file if it doesn't exist or overwrite is true
|
|
281
|
+
const writeIfNeeded = async (filePath, content) => {
|
|
282
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
283
|
+
if (!exists || overwrite) {
|
|
284
|
+
await fs.promises.writeFile(filePath, content, 'utf-8');
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// 1. Create .github/copilot-instructions.md
|
|
289
|
+
const copilotInstructionsPath = path.join(githubDir, 'copilot-instructions.md');
|
|
290
|
+
const copilotInstructionsContent = generateCopilotInstructionsContent(projectMeta);
|
|
291
|
+
await writeIfNeeded(copilotInstructionsPath, copilotInstructionsContent);
|
|
292
|
+
|
|
293
|
+
// 2. Create .github/instructions/typescript.instructions.md
|
|
294
|
+
const tsInstructionsPath = path.join(instructionsDir, 'typescript.instructions.md');
|
|
295
|
+
const tsInstructionsContent = generateTypeScriptInstructionsContent();
|
|
296
|
+
await writeIfNeeded(tsInstructionsPath, tsInstructionsContent);
|
|
297
|
+
|
|
298
|
+
// 3. Create .github/instructions/testing.instructions.md
|
|
299
|
+
const testInstructionsPath = path.join(instructionsDir, 'testing.instructions.md');
|
|
300
|
+
const testInstructionsContent = generateTestingInstructionsContent();
|
|
301
|
+
await writeIfNeeded(testInstructionsPath, testInstructionsContent);
|
|
302
|
+
|
|
303
|
+
// 4. Create .github/prompts/red.prompt.md
|
|
304
|
+
const redPromptPath = path.join(promptsDir, 'red.prompt.md');
|
|
305
|
+
const redPromptContent = generateRedPromptContent();
|
|
306
|
+
await writeIfNeeded(redPromptPath, redPromptContent);
|
|
307
|
+
|
|
308
|
+
// 5. Create .github/prompts/green.prompt.md
|
|
309
|
+
const greenPromptPath = path.join(promptsDir, 'green.prompt.md');
|
|
310
|
+
const greenPromptContent = generateGreenPromptContent();
|
|
311
|
+
await writeIfNeeded(greenPromptPath, greenPromptContent);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Generate .github/copilot-instructions.md content
|
|
316
|
+
*/
|
|
317
|
+
function generateCopilotInstructionsContent(meta) {
|
|
318
|
+
const packageManager = meta.testCommand?.includes('bun') ? 'bun' : 'npm';
|
|
319
|
+
|
|
320
|
+
return `# Forge Workflow Framework
|
|
321
|
+
|
|
322
|
+
This project uses the **Forge 7-Stage TDD Workflow** for development with GitHub Copilot.
|
|
323
|
+
|
|
324
|
+
## Quick Start
|
|
325
|
+
|
|
326
|
+
\`\`\`bash
|
|
327
|
+
${packageManager} install # Install dependencies
|
|
328
|
+
${meta.testCommand} # Run tests
|
|
329
|
+
${meta.buildCommand} # Build project
|
|
330
|
+
\`\`\`
|
|
331
|
+
|
|
332
|
+
## Tech Stack
|
|
333
|
+
|
|
334
|
+
${meta.language ? `- **Language**: ${meta.language} (strict mode enabled)` : '- **Language**: JavaScript'}
|
|
335
|
+
- **Package Manager**: ${packageManager}
|
|
336
|
+
- **Testing**: TDD-first approach (tests before implementation)
|
|
337
|
+
- **Security**: OWASP Top 10 compliance required
|
|
338
|
+
- **Version Control**: Git with conventional commits
|
|
339
|
+
|
|
340
|
+
## Forge 7-Stage TDD Workflow
|
|
341
|
+
|
|
342
|
+
### Utility: /status
|
|
343
|
+
Check current context and active work
|
|
344
|
+
- Review git status and recent commits
|
|
345
|
+
- Check Beads issues (if installed) for active work
|
|
346
|
+
- Identify current workflow stage
|
|
347
|
+
|
|
348
|
+
### Stage 1: /plan
|
|
349
|
+
Create implementation plan
|
|
350
|
+
- Research with web search
|
|
351
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
352
|
+
- **Security**: Identify OWASP Top 10 considerations
|
|
353
|
+
- Generate plan, create Beads issue, break into TDD cycles
|
|
354
|
+
|
|
355
|
+
### Stage 2: /dev
|
|
356
|
+
**TDD development (RED-GREEN-REFACTOR)**
|
|
357
|
+
- **RED**: Write failing test FIRST
|
|
358
|
+
- **GREEN**: Implement minimal code to pass
|
|
359
|
+
- **REFACTOR**: Clean up and optimize
|
|
360
|
+
- Commit after each cycle
|
|
361
|
+
- Push regularly to remote
|
|
362
|
+
|
|
363
|
+
### Stage 3: /validate
|
|
364
|
+
Validation and quality gates
|
|
365
|
+
- Type checking${meta.language === 'TypeScript' ? ' (TypeScript strict mode)' : ''}
|
|
366
|
+
- Linting (ESLint - no errors allowed)
|
|
367
|
+
- Security scanning (npm audit, OWASP checks)
|
|
368
|
+
- Test suite (all tests must pass)
|
|
369
|
+
- Code coverage verification (80%+ required)
|
|
370
|
+
|
|
371
|
+
### Stage 4: /ship
|
|
372
|
+
Create pull request
|
|
373
|
+
- Generate PR body with context
|
|
374
|
+
- Reference Beads issues
|
|
375
|
+
- Include test coverage metrics
|
|
376
|
+
- Link to research and plan documents
|
|
377
|
+
|
|
378
|
+
### Stage 5: /review
|
|
379
|
+
Address ALL PR feedback
|
|
380
|
+
- GitHub Actions failures
|
|
381
|
+
- Code review comments
|
|
382
|
+
- AI review tools (Greptile, CodeRabbit if configured)
|
|
383
|
+
- Security scan results
|
|
384
|
+
- **IMPORTANT**: Resolve all comment threads before merge
|
|
385
|
+
|
|
386
|
+
### Stage 6: /premerge
|
|
387
|
+
Merge and cleanup
|
|
388
|
+
- Update documentation
|
|
389
|
+
- Merge pull request (squash commits only)
|
|
390
|
+
- Delete feature branch
|
|
391
|
+
- Archive completed work
|
|
392
|
+
- Close Beads issues
|
|
393
|
+
|
|
394
|
+
### Stage 7: /verify
|
|
395
|
+
Final documentation cross-check
|
|
396
|
+
- Verify all docs updated correctly
|
|
397
|
+
- Check for broken links
|
|
398
|
+
- Validate code examples
|
|
399
|
+
- Ensure consistency across documentation
|
|
400
|
+
|
|
401
|
+
## Core Principles
|
|
402
|
+
|
|
403
|
+
### 1. TDD-First Development (MANDATORY)
|
|
404
|
+
- Tests written UPFRONT in RED-GREEN-REFACTOR cycles
|
|
405
|
+
- **NO implementation without failing test first**
|
|
406
|
+
- Commit after each GREEN cycle
|
|
407
|
+
- Maintain high code coverage (80%+ minimum)
|
|
408
|
+
|
|
409
|
+
### 2. Research-First Approach
|
|
410
|
+
- All features start with comprehensive research
|
|
411
|
+
- Use web search for best practices and security analysis
|
|
412
|
+
- Document findings before implementation
|
|
413
|
+
- **Include OWASP Top 10 analysis for security-critical features**
|
|
414
|
+
|
|
415
|
+
### 3. Security Built-In
|
|
416
|
+
- **OWASP Top 10** analysis for every new feature:
|
|
417
|
+
- A01: Broken Access Control
|
|
418
|
+
- A02: Cryptographic Failures
|
|
419
|
+
- A03: Injection
|
|
420
|
+
- A04: Insecure Design
|
|
421
|
+
- A05: Security Misconfiguration
|
|
422
|
+
- A06: Vulnerable and Outdated Components
|
|
423
|
+
- A07: Identification and Authentication Failures
|
|
424
|
+
- A08: Software and Data Integrity Failures
|
|
425
|
+
- A09: Security Logging and Monitoring Failures
|
|
426
|
+
- A10: Server-Side Request Forgery (SSRF)
|
|
427
|
+
- Security test scenarios identified upfront
|
|
428
|
+
- Automated scans + manual review
|
|
429
|
+
- Input validation and sanitization
|
|
430
|
+
|
|
431
|
+
### 4. Documentation Progressive
|
|
432
|
+
- Updated at relevant stages (not deferred to end)
|
|
433
|
+
- Cross-checked at /verify stage
|
|
434
|
+
- Never accumulate documentation debt
|
|
435
|
+
- Keep README, docs/, and inline comments synchronized
|
|
436
|
+
|
|
437
|
+
## Git Workflow
|
|
438
|
+
|
|
439
|
+
**Branch naming**:
|
|
440
|
+
- \`feat/<feature-slug>\` - New features
|
|
441
|
+
- \`fix/<bug-slug>\` - Bug fixes
|
|
442
|
+
- \`docs/<doc-slug>\` - Documentation updates
|
|
443
|
+
|
|
444
|
+
**Commit pattern** (conventional commits):
|
|
445
|
+
\`\`\`bash
|
|
446
|
+
git commit -m "test: add validation tests" # RED phase
|
|
447
|
+
git commit -m "feat: implement validation" # GREEN phase
|
|
448
|
+
git commit -m "refactor: extract helpers" # REFACTOR phase
|
|
449
|
+
\`\`\`
|
|
450
|
+
|
|
451
|
+
**Pre-commit hooks** (automatic via Lefthook):
|
|
452
|
+
- TDD enforcement (source files must have tests)
|
|
453
|
+
- Interactive prompts (option to unstage, continue, or abort)
|
|
454
|
+
|
|
455
|
+
**Pre-push hooks** (automatic):
|
|
456
|
+
- Branch protection (blocks direct push to main/master)
|
|
457
|
+
- ESLint check (blocks on errors)
|
|
458
|
+
- Test suite (all tests must pass)
|
|
459
|
+
|
|
460
|
+
## MCP Servers (Enhanced Capabilities)
|
|
461
|
+
|
|
462
|
+
Configure these MCP servers in \`.mcp.json\`:
|
|
463
|
+
|
|
464
|
+
- **github**: Repository integration (usually built-in)
|
|
465
|
+
- **parallel-ai**: Web research and data enrichment
|
|
466
|
+
- **context7**: Up-to-date library documentation
|
|
467
|
+
|
|
468
|
+
## Issue Tracking with Beads
|
|
469
|
+
|
|
470
|
+
Use **Beads** for persistent tracking across sessions:
|
|
471
|
+
|
|
472
|
+
\`\`\`bash
|
|
473
|
+
bd create "Feature name" # Create issue
|
|
474
|
+
bd update <id> --status in_progress # Claim work
|
|
475
|
+
bd update <id> --append-notes "Progress" # Add notes
|
|
476
|
+
bd close <id> # Complete
|
|
477
|
+
bd sync # Sync with git
|
|
478
|
+
\`\`\`
|
|
479
|
+
|
|
480
|
+
## Code Quality Standards
|
|
481
|
+
|
|
482
|
+
${meta.language === 'TypeScript' ? `
|
|
483
|
+
### TypeScript
|
|
484
|
+
- Strict mode enabled (\`strict: true\` in tsconfig.json)
|
|
485
|
+
- No \`any\` types without explicit justification
|
|
486
|
+
- Prefer interfaces over types for object shapes
|
|
487
|
+
- Use const assertions for literal types
|
|
488
|
+
` : ''}
|
|
489
|
+
|
|
490
|
+
### Testing
|
|
491
|
+
- TDD-first: Write failing test BEFORE implementation
|
|
492
|
+
- Use descriptive test names ("it should...")
|
|
493
|
+
- Arrange-Act-Assert pattern
|
|
494
|
+
- Mock external dependencies
|
|
495
|
+
- Test edge cases and error scenarios
|
|
496
|
+
|
|
497
|
+
### Security
|
|
498
|
+
- Validate all user input
|
|
499
|
+
- Sanitize output to prevent XSS
|
|
500
|
+
- Use parameterized queries (prevent SQL injection)
|
|
501
|
+
- Implement proper authentication and authorization
|
|
502
|
+
- Never commit secrets or credentials
|
|
503
|
+
|
|
504
|
+
## Additional Resources
|
|
505
|
+
|
|
506
|
+
- **Workflow Guide**: \`docs/WORKFLOW.md\`
|
|
507
|
+
- **Architecture**: \`docs/ARCHITECTURE.md\`
|
|
508
|
+
- **Configuration**: \`docs/CONFIGURATION.md\`
|
|
509
|
+
`;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Generate .github/instructions/typescript.instructions.md content
|
|
514
|
+
*/
|
|
515
|
+
function generateTypeScriptInstructionsContent() {
|
|
516
|
+
return `---
|
|
517
|
+
applyTo: "**/*.ts"
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
# TypeScript Guidelines
|
|
521
|
+
|
|
522
|
+
When working with TypeScript files in this project:
|
|
523
|
+
|
|
524
|
+
## Type Safety
|
|
525
|
+
- **strict mode is enabled** - No shortcuts with types
|
|
526
|
+
- Avoid \`any\` type - Use \`unknown\` and type guards instead
|
|
527
|
+
- Prefer interfaces over type aliases for object shapes
|
|
528
|
+
- Use const assertions for literal types
|
|
529
|
+
|
|
530
|
+
## Code Style
|
|
531
|
+
- Use explicit return types for public functions
|
|
532
|
+
- Leverage type inference for local variables
|
|
533
|
+
- Use utility types (\`Partial\`, \`Pick\`, \`Omit\`, etc.) appropriately
|
|
534
|
+
- Document complex types with JSDoc comments
|
|
535
|
+
|
|
536
|
+
## Common Patterns
|
|
537
|
+
- Use discriminated unions for state management
|
|
538
|
+
- Prefer \`readonly\` for immutable data
|
|
539
|
+
- Use \`unknown\` instead of \`any\` for truly unknown types
|
|
540
|
+
- Leverage template literal types for string validation
|
|
541
|
+
|
|
542
|
+
## Error Handling
|
|
543
|
+
- Create custom error types for domain-specific errors
|
|
544
|
+
- Use type guards to narrow error types
|
|
545
|
+
- Always type catch clauses (\`catch (error: unknown)\`)
|
|
546
|
+
`;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Generate .github/instructions/testing.instructions.md content
|
|
551
|
+
*/
|
|
552
|
+
function generateTestingInstructionsContent() {
|
|
553
|
+
return `---
|
|
554
|
+
applyTo: "**/*.test.ts"
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
# Testing Guidelines
|
|
558
|
+
|
|
559
|
+
When writing tests in this project:
|
|
560
|
+
|
|
561
|
+
## TDD-First Approach
|
|
562
|
+
- **Write failing test BEFORE implementation** (RED phase)
|
|
563
|
+
- Run test to confirm it fails for the right reason
|
|
564
|
+
- Implement minimal code to make test pass (GREEN phase)
|
|
565
|
+
- Refactor while keeping tests green (REFACTOR phase)
|
|
566
|
+
|
|
567
|
+
## Test Structure
|
|
568
|
+
- Use descriptive test names: "it should [expected behavior] when [condition]"
|
|
569
|
+
- Follow Arrange-Act-Assert pattern:
|
|
570
|
+
- **Arrange**: Set up test data and preconditions
|
|
571
|
+
- **Act**: Execute the code under test
|
|
572
|
+
- **Assert**: Verify the expected outcome
|
|
573
|
+
|
|
574
|
+
## Best Practices
|
|
575
|
+
- One assertion per test (or closely related assertions)
|
|
576
|
+
- Test edge cases and error scenarios
|
|
577
|
+
- Mock external dependencies (APIs, databases, file system)
|
|
578
|
+
- Use fixtures for complex test data
|
|
579
|
+
- Keep tests fast and independent
|
|
580
|
+
|
|
581
|
+
## Coverage
|
|
582
|
+
- Aim for 80%+ code coverage
|
|
583
|
+
- Focus on testing behavior, not implementation details
|
|
584
|
+
- Test public interfaces, not private methods
|
|
585
|
+
- Include integration tests for critical paths
|
|
586
|
+
|
|
587
|
+
## Security Testing
|
|
588
|
+
- Test input validation and sanitization
|
|
589
|
+
- Verify authentication and authorization
|
|
590
|
+
- Test error messages don't leak sensitive data
|
|
591
|
+
- Include security-specific test cases for OWASP Top 10
|
|
592
|
+
`;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Generate .github/prompts/red.prompt.md content
|
|
597
|
+
*/
|
|
598
|
+
function generateRedPromptContent() {
|
|
599
|
+
return `Write a failing test for the following requirement.
|
|
600
|
+
|
|
601
|
+
Follow TDD red-green-refactor cycle:
|
|
602
|
+
- Test should fail initially (RED phase)
|
|
603
|
+
- Use descriptive test name
|
|
604
|
+
- Follow Arrange-Act-Assert pattern
|
|
605
|
+
- Test one behavior per test case
|
|
606
|
+
|
|
607
|
+
Do NOT implement the feature yet - only write the test.
|
|
608
|
+
`;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Generate .github/prompts/green.prompt.md content
|
|
613
|
+
*/
|
|
614
|
+
function generateGreenPromptContent() {
|
|
615
|
+
return `Implement minimal code to make the failing test pass.
|
|
616
|
+
|
|
617
|
+
Follow TDD principles:
|
|
618
|
+
- Write only enough code to pass the test (GREEN phase)
|
|
619
|
+
- Keep implementation simple and focused
|
|
620
|
+
- Don't add features not covered by tests
|
|
621
|
+
- Ensure all tests pass
|
|
622
|
+
|
|
623
|
+
Refactoring comes after this step - focus on making it work first.
|
|
624
|
+
`;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Generate Cursor configuration files
|
|
629
|
+
* @param {string} projectPath - Path to the project root
|
|
630
|
+
* @param {Object} options - Generation options
|
|
631
|
+
* @param {boolean} options.overwrite - Whether to overwrite existing files (default: false)
|
|
632
|
+
* @returns {Promise<void>}
|
|
633
|
+
*/
|
|
634
|
+
async function generateCursorConfig(projectPath, options = {}) {
|
|
635
|
+
const { overwrite = false } = options;
|
|
636
|
+
|
|
637
|
+
// Detect project metadata
|
|
638
|
+
const projectMeta = await detectProjectMetadata(projectPath);
|
|
639
|
+
|
|
640
|
+
// Create .cursor/rules directory structure
|
|
641
|
+
const cursorDir = path.join(projectPath, '.cursor');
|
|
642
|
+
const rulesDir = path.join(cursorDir, 'rules');
|
|
643
|
+
|
|
644
|
+
await fs.promises.mkdir(rulesDir, { recursive: true });
|
|
645
|
+
|
|
646
|
+
// Helper to write file if it doesn't exist or overwrite is true
|
|
647
|
+
const writeIfNeeded = async (filePath, content) => {
|
|
648
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
649
|
+
if (!exists || overwrite) {
|
|
650
|
+
await fs.promises.writeFile(filePath, content, 'utf-8');
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// 1. Create .cursor/rules/forge-workflow.mdc
|
|
655
|
+
const workflowPath = path.join(rulesDir, 'forge-workflow.mdc');
|
|
656
|
+
const workflowContent = generateCursorWorkflowContent(projectMeta);
|
|
657
|
+
await writeIfNeeded(workflowPath, workflowContent);
|
|
658
|
+
|
|
659
|
+
// 2. Create .cursor/rules/tdd-enforcement.mdc
|
|
660
|
+
const tddPath = path.join(rulesDir, 'tdd-enforcement.mdc');
|
|
661
|
+
const tddContent = generateCursorTddContent();
|
|
662
|
+
await writeIfNeeded(tddPath, tddContent);
|
|
663
|
+
|
|
664
|
+
// 3. Create .cursor/rules/security-scanning.mdc
|
|
665
|
+
const securityPath = path.join(rulesDir, 'security-scanning.mdc');
|
|
666
|
+
const securityContent = generateCursorSecurityContent();
|
|
667
|
+
await writeIfNeeded(securityPath, securityContent);
|
|
668
|
+
|
|
669
|
+
// 4. Create .cursor/rules/documentation.mdc
|
|
670
|
+
const docsPath = path.join(rulesDir, 'documentation.mdc');
|
|
671
|
+
const docsContent = generateCursorDocumentationContent();
|
|
672
|
+
await writeIfNeeded(docsPath, docsContent);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Generate .cursor/rules/forge-workflow.mdc content
|
|
677
|
+
*/
|
|
678
|
+
function generateCursorWorkflowContent(meta) {
|
|
679
|
+
const packageManager = meta.testCommand?.includes('bun') ? 'bun' : 'npm';
|
|
680
|
+
|
|
681
|
+
return `---
|
|
682
|
+
description: "When working with Forge workflow stages"
|
|
683
|
+
alwaysApply: true
|
|
684
|
+
---
|
|
685
|
+
|
|
686
|
+
# Forge 7-Stage TDD Workflow
|
|
687
|
+
|
|
688
|
+
Always follow these stages in order:
|
|
689
|
+
|
|
690
|
+
## Utility: /status
|
|
691
|
+
Check current context and active work
|
|
692
|
+
- Review git status and recent commits
|
|
693
|
+
- Check Beads issues (if installed) for active work
|
|
694
|
+
- Identify current workflow stage
|
|
695
|
+
|
|
696
|
+
## Stage 1: /plan
|
|
697
|
+
Create implementation plan
|
|
698
|
+
- Research with parallel-ai
|
|
699
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
700
|
+
- **Security**: OWASP Top 10 analysis
|
|
701
|
+
- Generate plan, create Beads issue, break into TDD cycles
|
|
702
|
+
|
|
703
|
+
## Stage 2: /dev
|
|
704
|
+
**TDD development (RED-GREEN-REFACTOR)**
|
|
705
|
+
- **RED**: Write failing test FIRST
|
|
706
|
+
- **GREEN**: Implement minimal code to pass
|
|
707
|
+
- **REFACTOR**: Clean up and optimize
|
|
708
|
+
- Commit after each cycle
|
|
709
|
+
- Push regularly to remote
|
|
710
|
+
|
|
711
|
+
## Stage 3: /validate
|
|
712
|
+
Validation (type/lint/tests/security)
|
|
713
|
+
- Type checking${meta.language === 'TypeScript' ? ' (TypeScript strict mode)' : ''}
|
|
714
|
+
- Linting (ESLint - no errors)
|
|
715
|
+
- Security scanning (npm audit, OWASP)
|
|
716
|
+
- Test suite (all tests must pass)
|
|
717
|
+
- Code coverage (80%+ required)
|
|
718
|
+
|
|
719
|
+
## Stage 4: /ship
|
|
720
|
+
Create PR with documentation
|
|
721
|
+
- Generate PR body with context
|
|
722
|
+
- Reference Beads issues
|
|
723
|
+
- Include test coverage metrics
|
|
724
|
+
- Link to research and plan documents
|
|
725
|
+
|
|
726
|
+
## Stage 5: /review
|
|
727
|
+
Address ALL PR feedback
|
|
728
|
+
- GitHub Actions failures
|
|
729
|
+
- Code review comments
|
|
730
|
+
- AI review tools (Greptile, CodeRabbit)
|
|
731
|
+
- Security scan results
|
|
732
|
+
- **IMPORTANT**: Resolve all comment threads
|
|
733
|
+
|
|
734
|
+
## Stage 6: /premerge
|
|
735
|
+
Update docs, merge PR, cleanup
|
|
736
|
+
- Update documentation
|
|
737
|
+
- Merge pull request (squash commits only)
|
|
738
|
+
- Delete feature branch
|
|
739
|
+
- Archive completed work
|
|
740
|
+
- Close Beads issues
|
|
741
|
+
|
|
742
|
+
## Stage 7: /verify
|
|
743
|
+
Final documentation verification
|
|
744
|
+
- Verify all docs updated correctly
|
|
745
|
+
- Check for broken links
|
|
746
|
+
- Validate code examples
|
|
747
|
+
- Ensure consistency across documentation
|
|
748
|
+
|
|
749
|
+
## TDD Requirements
|
|
750
|
+
|
|
751
|
+
**MANDATORY - No implementation without failing test**:
|
|
752
|
+
- Write test FIRST (RED phase)
|
|
753
|
+
- Implement minimal code to pass (GREEN phase)
|
|
754
|
+
- Refactor and commit (REFACTOR phase)
|
|
755
|
+
- No code changes without corresponding tests
|
|
756
|
+
|
|
757
|
+
## Tech Stack
|
|
758
|
+
|
|
759
|
+
${meta.language ? `- **Language**: ${meta.language}` : '- **Language**: JavaScript'}
|
|
760
|
+
- **Package Manager**: ${packageManager}
|
|
761
|
+
- **Testing**: TDD-first approach (tests before implementation)
|
|
762
|
+
- **Security**: OWASP Top 10 compliance
|
|
763
|
+
- **Version Control**: Git with conventional commits
|
|
764
|
+
|
|
765
|
+
## Cursor Native Modes
|
|
766
|
+
|
|
767
|
+
Leverage Cursor's built-in modes:
|
|
768
|
+
- **Agent Mode** (default): Full tools for implementation
|
|
769
|
+
- **Ask Mode**: Read-only exploration and learning
|
|
770
|
+
- **Plan Mode** (Shift+Tab): Create plans before coding
|
|
771
|
+
- **Debug Mode**: Specialized bug hunting with instrumentation
|
|
772
|
+
|
|
773
|
+
Use Plan Mode for complex features and architectural decisions.
|
|
774
|
+
`;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Generate .cursor/rules/tdd-enforcement.mdc content
|
|
779
|
+
*/
|
|
780
|
+
function generateCursorTddContent() {
|
|
781
|
+
return `---
|
|
782
|
+
description: "TDD patterns and enforcement"
|
|
783
|
+
globs: ["**/*.ts", "**/*.js", "**/*.test.ts", "**/*.test.js"]
|
|
784
|
+
---
|
|
785
|
+
|
|
786
|
+
# TDD Enforcement
|
|
787
|
+
|
|
788
|
+
## RED-GREEN-REFACTOR Cycle
|
|
789
|
+
|
|
790
|
+
### RED Phase (Write Failing Test)
|
|
791
|
+
1. **Write test FIRST** - Before any implementation
|
|
792
|
+
2. Run test to confirm it fails for the right reason
|
|
793
|
+
3. Commit: \`git commit -m "test: add [feature] tests (RED)"\`
|
|
794
|
+
|
|
795
|
+
### GREEN Phase (Make Test Pass)
|
|
796
|
+
1. **Write minimal code** to make the test pass
|
|
797
|
+
2. Keep implementation simple and focused
|
|
798
|
+
3. Don't add features not covered by tests
|
|
799
|
+
4. Commit: \`git commit -m "feat: implement [feature] (GREEN)"\`
|
|
800
|
+
|
|
801
|
+
### REFACTOR Phase (Clean Up)
|
|
802
|
+
1. Improve code while keeping tests green
|
|
803
|
+
2. Extract helpers, remove duplication
|
|
804
|
+
3. Optimize performance if needed
|
|
805
|
+
4. Commit: \`git commit -m "refactor: [description]"\`
|
|
806
|
+
|
|
807
|
+
## Test Structure
|
|
808
|
+
|
|
809
|
+
### Naming Convention
|
|
810
|
+
\`\`\`javascript
|
|
811
|
+
test('should [expected behavior] when [condition]', async () => {
|
|
812
|
+
// Arrange: Set up test data
|
|
813
|
+
// Act: Execute code under test
|
|
814
|
+
// Assert: Verify outcome
|
|
815
|
+
});
|
|
816
|
+
\`\`\`
|
|
817
|
+
|
|
818
|
+
### Best Practices
|
|
819
|
+
- One assertion per test (or closely related assertions)
|
|
820
|
+
- Test edge cases and error scenarios
|
|
821
|
+
- Mock external dependencies (APIs, databases, file system)
|
|
822
|
+
- Use fixtures for complex test data
|
|
823
|
+
- Keep tests fast and independent
|
|
824
|
+
|
|
825
|
+
## Coverage Requirements
|
|
826
|
+
- Minimum 80% code coverage
|
|
827
|
+
- Focus on testing behavior, not implementation
|
|
828
|
+
- Test public interfaces, not private methods
|
|
829
|
+
- Include integration tests for critical paths
|
|
830
|
+
|
|
831
|
+
## Security Testing
|
|
832
|
+
- Test input validation and sanitization
|
|
833
|
+
- Verify authentication and authorization
|
|
834
|
+
- Test error messages don't leak sensitive data
|
|
835
|
+
- Include security-specific test cases for OWASP Top 10
|
|
836
|
+
`;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Generate .cursor/rules/security-scanning.mdc content
|
|
841
|
+
*/
|
|
842
|
+
function generateCursorSecurityContent() {
|
|
843
|
+
return `---
|
|
844
|
+
description: "OWASP Top 10 security checks"
|
|
845
|
+
---
|
|
846
|
+
|
|
847
|
+
# Security Scanning Guidelines
|
|
848
|
+
|
|
849
|
+
## OWASP Top 10 (2021)
|
|
850
|
+
|
|
851
|
+
For every new feature, analyze these security risks:
|
|
852
|
+
|
|
853
|
+
### A01: Broken Access Control
|
|
854
|
+
- Verify authorization checks on all protected resources
|
|
855
|
+
- Test that users can't access data they shouldn't
|
|
856
|
+
- Implement principle of least privilege
|
|
857
|
+
|
|
858
|
+
### A02: Cryptographic Failures
|
|
859
|
+
- Never store passwords in plaintext
|
|
860
|
+
- Use strong encryption algorithms (AES-256, RSA-2048+)
|
|
861
|
+
- Protect data in transit (HTTPS, TLS 1.2+)
|
|
862
|
+
- Secure key management
|
|
863
|
+
|
|
864
|
+
### A03: Injection
|
|
865
|
+
- **SQL Injection**: Use parameterized queries
|
|
866
|
+
- **XSS**: Sanitize output, use Content Security Policy
|
|
867
|
+
- **Command Injection**: Validate and sanitize all inputs
|
|
868
|
+
- Never concatenate user input into commands or queries
|
|
869
|
+
|
|
870
|
+
### A04: Insecure Design
|
|
871
|
+
- Security requirements defined upfront
|
|
872
|
+
- Threat modeling for new features
|
|
873
|
+
- Defense in depth (multiple security layers)
|
|
874
|
+
- Secure defaults
|
|
875
|
+
|
|
876
|
+
### A05: Security Misconfiguration
|
|
877
|
+
- Remove default credentials
|
|
878
|
+
- Disable unnecessary features and services
|
|
879
|
+
- Keep dependencies up to date
|
|
880
|
+
- Implement security headers
|
|
881
|
+
|
|
882
|
+
### A06: Vulnerable and Outdated Components
|
|
883
|
+
- Regular dependency audits (\`npm audit\`)
|
|
884
|
+
- Update dependencies promptly
|
|
885
|
+
- Use Software Composition Analysis (SCA) tools
|
|
886
|
+
- Monitor security advisories
|
|
887
|
+
|
|
888
|
+
### A07: Identification and Authentication Failures
|
|
889
|
+
- Implement multi-factor authentication where appropriate
|
|
890
|
+
- Secure password storage (bcrypt, Argon2)
|
|
891
|
+
- Protect against brute force attacks (rate limiting)
|
|
892
|
+
- Secure session management
|
|
893
|
+
|
|
894
|
+
### A08: Software and Data Integrity Failures
|
|
895
|
+
- Verify digital signatures
|
|
896
|
+
- Use integrity checks for critical data
|
|
897
|
+
- Implement code signing
|
|
898
|
+
- Secure CI/CD pipelines
|
|
899
|
+
|
|
900
|
+
### A09: Security Logging and Monitoring Failures
|
|
901
|
+
- Log all security-relevant events
|
|
902
|
+
- Protect logs from tampering
|
|
903
|
+
- Implement alerting for suspicious activity
|
|
904
|
+
- Regular log review
|
|
905
|
+
|
|
906
|
+
### A10: Server-Side Request Forgery (SSRF)
|
|
907
|
+
- Validate and sanitize all URLs
|
|
908
|
+
- Use allowlists for external requests
|
|
909
|
+
- Disable unnecessary protocols
|
|
910
|
+
- Network segmentation
|
|
911
|
+
|
|
912
|
+
## Security Testing Checklist
|
|
913
|
+
|
|
914
|
+
For each feature:
|
|
915
|
+
- [ ] Input validation implemented and tested
|
|
916
|
+
- [ ] Output sanitization verified
|
|
917
|
+
- [ ] Authentication and authorization tested
|
|
918
|
+
- [ ] Error messages don't leak sensitive data
|
|
919
|
+
- [ ] Dependencies scanned for vulnerabilities
|
|
920
|
+
- [ ] Security test cases added to test suite
|
|
921
|
+
- [ ] OWASP Top 10 risks analyzed
|
|
922
|
+
`;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Generate .cursor/rules/documentation.mdc content
|
|
927
|
+
*/
|
|
928
|
+
function generateCursorDocumentationContent() {
|
|
929
|
+
return `---
|
|
930
|
+
description: "Progressive documentation standards"
|
|
931
|
+
---
|
|
932
|
+
|
|
933
|
+
# Documentation Standards
|
|
934
|
+
|
|
935
|
+
## Progressive Documentation
|
|
936
|
+
|
|
937
|
+
Update documentation at relevant stages (not deferred to end):
|
|
938
|
+
|
|
939
|
+
### During /plan (Stage 1)
|
|
940
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
941
|
+
- Include decision rationale
|
|
942
|
+
- Document alternatives considered
|
|
943
|
+
- Security considerations (OWASP analysis)
|
|
944
|
+
|
|
945
|
+
### During /plan (Stage 3)
|
|
946
|
+
- Create implementation plan in \`.claude/plans/<feature-slug>.md\`
|
|
947
|
+
- Document test scenarios
|
|
948
|
+
- Identify affected files
|
|
949
|
+
|
|
950
|
+
### During /dev (Stage 4)
|
|
951
|
+
- Add inline code comments for complex logic
|
|
952
|
+
- Update JSDoc/TSDoc for public APIs
|
|
953
|
+
- Keep comments synchronized with code changes
|
|
954
|
+
|
|
955
|
+
### During /ship (Stage 6)
|
|
956
|
+
- Update README if user-facing changes
|
|
957
|
+
- Update CHANGELOG with conventional commit summary
|
|
958
|
+
- Document breaking changes
|
|
959
|
+
- Add migration guide if needed
|
|
960
|
+
|
|
961
|
+
### During /verify (Stage 7)
|
|
962
|
+
- Cross-check all documentation updated
|
|
963
|
+
- Validate code examples still work
|
|
964
|
+
- Check for broken internal links
|
|
965
|
+
- Ensure terminology consistency
|
|
966
|
+
|
|
967
|
+
## Documentation Types
|
|
968
|
+
|
|
969
|
+
### Code Comments
|
|
970
|
+
- **What to comment**: Why, not what
|
|
971
|
+
- Document non-obvious decisions
|
|
972
|
+
- Explain complex algorithms
|
|
973
|
+
- Note security considerations
|
|
974
|
+
- Reference tickets/issues for context
|
|
975
|
+
|
|
976
|
+
### API Documentation
|
|
977
|
+
- Use JSDoc/TSDoc for public APIs
|
|
978
|
+
- Include parameter types and return types
|
|
979
|
+
- Provide usage examples
|
|
980
|
+
- Document error conditions
|
|
981
|
+
- List breaking changes in version updates
|
|
982
|
+
|
|
983
|
+
### README Updates
|
|
984
|
+
- Keep Quick Start section current
|
|
985
|
+
- Update feature list
|
|
986
|
+
- Maintain installation instructions
|
|
987
|
+
- Document configuration options
|
|
988
|
+
- Include troubleshooting section
|
|
989
|
+
|
|
990
|
+
## Documentation Quality
|
|
991
|
+
|
|
992
|
+
### Consistency
|
|
993
|
+
- Use consistent terminology across docs
|
|
994
|
+
- Follow project style guide
|
|
995
|
+
- Maintain consistent formatting
|
|
996
|
+
- Use same voice and tone
|
|
997
|
+
|
|
998
|
+
### Clarity
|
|
999
|
+
- Write for your audience (developers, users, etc.)
|
|
1000
|
+
- Use examples liberally
|
|
1001
|
+
- Avoid jargon without explanation
|
|
1002
|
+
- Keep sentences short and clear
|
|
1003
|
+
|
|
1004
|
+
### Maintainability
|
|
1005
|
+
- Link to code where appropriate
|
|
1006
|
+
- Use relative links for internal docs
|
|
1007
|
+
- Keep docs close to the code they describe
|
|
1008
|
+
- Remove outdated documentation promptly
|
|
1009
|
+
`;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Generate Kilo Code configuration file
|
|
1014
|
+
* @param {string} projectPath - Path to the project root
|
|
1015
|
+
* @param {Object} options - Generation options
|
|
1016
|
+
* @param {boolean} options.overwrite - Whether to overwrite existing files (default: false)
|
|
1017
|
+
* @returns {Promise<void>}
|
|
1018
|
+
*/
|
|
1019
|
+
async function generateKiloConfig(projectPath, options = {}) {
|
|
1020
|
+
const { overwrite = false } = options;
|
|
1021
|
+
|
|
1022
|
+
// Detect project metadata
|
|
1023
|
+
const projectMeta = await detectProjectMetadata(projectPath);
|
|
1024
|
+
|
|
1025
|
+
const kiloMdPath = path.join(projectPath, '.kilo.md');
|
|
1026
|
+
|
|
1027
|
+
// Check if file exists
|
|
1028
|
+
const exists = await fs.promises.access(kiloMdPath).then(() => true).catch(() => false);
|
|
1029
|
+
if (exists && !overwrite) {
|
|
1030
|
+
return; // Don't overwrite
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// Generate .kilo.md content (plain markdown, no frontmatter)
|
|
1034
|
+
const content = generateKiloMdContent(projectMeta);
|
|
1035
|
+
|
|
1036
|
+
await fs.promises.writeFile(kiloMdPath, content, 'utf-8');
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* Generate .kilo.md content
|
|
1041
|
+
*/
|
|
1042
|
+
function generateKiloMdContent(meta) {
|
|
1043
|
+
const packageManager = meta.testCommand?.includes('bun') ? 'bun' : 'npm';
|
|
1044
|
+
|
|
1045
|
+
return `# Forge Workflow Framework - Kilo Code
|
|
1046
|
+
|
|
1047
|
+
This project uses the **Forge 7-Stage TDD Workflow** with Kilo Code.
|
|
1048
|
+
|
|
1049
|
+
## Quick Start
|
|
1050
|
+
|
|
1051
|
+
\`\`\`bash
|
|
1052
|
+
${packageManager} install # Install dependencies
|
|
1053
|
+
${meta.testCommand} # Run tests
|
|
1054
|
+
${meta.buildCommand} # Build project
|
|
1055
|
+
\`\`\`
|
|
1056
|
+
|
|
1057
|
+
## Kilo Built-in Commands
|
|
1058
|
+
|
|
1059
|
+
Kilo Code provides built-in commands:
|
|
1060
|
+
- \`/plan\` - Create implementation plans (similar to Forge Stage 3)
|
|
1061
|
+
- \`/deploy\` - Deploy to production
|
|
1062
|
+
- \`/review\` - Code review assistance
|
|
1063
|
+
|
|
1064
|
+
These complement the Forge workflow stages below.
|
|
1065
|
+
|
|
1066
|
+
## Forge 7-Stage TDD Workflow
|
|
1067
|
+
|
|
1068
|
+
### Utility: /status
|
|
1069
|
+
Check current context and active work
|
|
1070
|
+
- Review git status and recent commits
|
|
1071
|
+
- Check Beads issues (if installed)
|
|
1072
|
+
|
|
1073
|
+
### Stage 1: /plan
|
|
1074
|
+
Create implementation plan
|
|
1075
|
+
- Research with web search
|
|
1076
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
1077
|
+
- Security: OWASP Top 10 analysis
|
|
1078
|
+
- Generate plan, create Beads issue, break into TDD cycles
|
|
1079
|
+
|
|
1080
|
+
### Stage 2: /dev
|
|
1081
|
+
**TDD development (RED-GREEN-REFACTOR)**
|
|
1082
|
+
- **RED**: Write failing test FIRST
|
|
1083
|
+
- **GREEN**: Implement minimal code to pass
|
|
1084
|
+
- **REFACTOR**: Clean up and optimize
|
|
1085
|
+
- Commit after each cycle
|
|
1086
|
+
|
|
1087
|
+
### Stage 3: /validate
|
|
1088
|
+
Validation (type/lint/tests/security)
|
|
1089
|
+
- Type checking${meta.language === 'TypeScript' ? ' (TypeScript strict mode)' : ''}
|
|
1090
|
+
- Linting (ESLint)
|
|
1091
|
+
- Security scanning
|
|
1092
|
+
- Test suite (all tests must pass)
|
|
1093
|
+
- Code coverage (80%+ required)
|
|
1094
|
+
|
|
1095
|
+
### Stage 4: /ship
|
|
1096
|
+
Create pull request
|
|
1097
|
+
- Generate PR body with context
|
|
1098
|
+
- Reference Beads issues
|
|
1099
|
+
- Include test coverage metrics
|
|
1100
|
+
|
|
1101
|
+
### Stage 5: /review
|
|
1102
|
+
Address ALL PR feedback
|
|
1103
|
+
- GitHub Actions failures
|
|
1104
|
+
- Code review comments
|
|
1105
|
+
- AI review tools
|
|
1106
|
+
- Resolve all comment threads
|
|
1107
|
+
|
|
1108
|
+
### Stage 6: /premerge
|
|
1109
|
+
Merge and cleanup
|
|
1110
|
+
- Update documentation
|
|
1111
|
+
- Merge PR (squash commits)
|
|
1112
|
+
- Delete feature branch
|
|
1113
|
+
- Close Beads issues
|
|
1114
|
+
|
|
1115
|
+
### Stage 7: /verify
|
|
1116
|
+
Final documentation verification
|
|
1117
|
+
- Verify all docs updated
|
|
1118
|
+
- Check for broken links
|
|
1119
|
+
- Validate code examples
|
|
1120
|
+
|
|
1121
|
+
## TDD Requirements
|
|
1122
|
+
|
|
1123
|
+
**MANDATORY**:
|
|
1124
|
+
- Write test FIRST (RED phase)
|
|
1125
|
+
- Implement minimal code to pass (GREEN phase)
|
|
1126
|
+
- Refactor and commit (REFACTOR phase)
|
|
1127
|
+
- No code changes without corresponding tests
|
|
1128
|
+
|
|
1129
|
+
## Tech Stack
|
|
1130
|
+
|
|
1131
|
+
${meta.language ? `- **Language**: ${meta.language}` : '- **Language**: JavaScript'}
|
|
1132
|
+
- **Package Manager**: ${packageManager}
|
|
1133
|
+
- **Testing**: TDD-first approach
|
|
1134
|
+
- **Security**: OWASP Top 10 compliance
|
|
1135
|
+
- **Version Control**: Git with conventional commits
|
|
1136
|
+
|
|
1137
|
+
## Security
|
|
1138
|
+
|
|
1139
|
+
For every new feature, analyze OWASP Top 10:
|
|
1140
|
+
- A01: Broken Access Control
|
|
1141
|
+
- A02: Cryptographic Failures
|
|
1142
|
+
- A03: Injection
|
|
1143
|
+
- A04: Insecure Design
|
|
1144
|
+
- A05: Security Misconfiguration
|
|
1145
|
+
- A06: Vulnerable and Outdated Components
|
|
1146
|
+
- A07: Authentication Failures
|
|
1147
|
+
- A08: Software and Data Integrity Failures
|
|
1148
|
+
- A09: Security Logging and Monitoring Failures
|
|
1149
|
+
- A10: Server-Side Request Forgery (SSRF)
|
|
1150
|
+
`;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Generate OpenCode configuration files
|
|
1155
|
+
* @param {string} projectPath - Path to the project root
|
|
1156
|
+
* @param {Object} options - Generation options
|
|
1157
|
+
* @param {boolean} options.overwrite - Whether to overwrite existing files (default: false)
|
|
1158
|
+
* @returns {Promise<void>}
|
|
1159
|
+
*/
|
|
1160
|
+
async function generateOpenCodeConfig(projectPath, options = {}) {
|
|
1161
|
+
const { overwrite = false } = options;
|
|
1162
|
+
|
|
1163
|
+
// Detect project metadata
|
|
1164
|
+
const projectMeta = await detectProjectMetadata(projectPath);
|
|
1165
|
+
|
|
1166
|
+
// Create .opencode/agents directory
|
|
1167
|
+
const opencodeDir = path.join(projectPath, '.opencode');
|
|
1168
|
+
const agentsDir = path.join(opencodeDir, 'agents');
|
|
1169
|
+
await fs.promises.mkdir(agentsDir, { recursive: true });
|
|
1170
|
+
|
|
1171
|
+
// Helper to write file if it doesn't exist or overwrite is true
|
|
1172
|
+
const writeIfNeeded = async (filePath, content) => {
|
|
1173
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
1174
|
+
if (!exists || overwrite) {
|
|
1175
|
+
await fs.promises.writeFile(filePath, content, 'utf-8');
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
// 1. Create opencode.json
|
|
1180
|
+
const opencodeJsonPath = path.join(projectPath, 'opencode.json');
|
|
1181
|
+
const opencodeJsonContent = generateOpenCodeJsonContent(projectMeta);
|
|
1182
|
+
await writeIfNeeded(opencodeJsonPath, opencodeJsonContent);
|
|
1183
|
+
|
|
1184
|
+
// 2. Create .opencode/agents/plan-review.md
|
|
1185
|
+
const planAgentPath = path.join(agentsDir, 'plan-review.md');
|
|
1186
|
+
const planAgentContent = generateOpenCodePlanAgentContent();
|
|
1187
|
+
await writeIfNeeded(planAgentPath, planAgentContent);
|
|
1188
|
+
|
|
1189
|
+
// 3. Create .opencode/agents/tdd-build.md
|
|
1190
|
+
const buildAgentPath = path.join(agentsDir, 'tdd-build.md');
|
|
1191
|
+
const buildAgentContent = generateOpenCodeBuildAgentContent();
|
|
1192
|
+
await writeIfNeeded(buildAgentPath, buildAgentContent);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Generate opencode.json content
|
|
1197
|
+
*/
|
|
1198
|
+
function generateOpenCodeJsonContent(_meta) {
|
|
1199
|
+
return JSON.stringify({
|
|
1200
|
+
"$schema": "https://opencode.ai/config.json",
|
|
1201
|
+
"agent": {
|
|
1202
|
+
"build": {
|
|
1203
|
+
"mode": "primary",
|
|
1204
|
+
"model": "anthropic/claude-sonnet-4-20250514",
|
|
1205
|
+
"tools": {
|
|
1206
|
+
"write": true,
|
|
1207
|
+
"edit": true,
|
|
1208
|
+
"bash": true
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
"plan": {
|
|
1212
|
+
"mode": "primary",
|
|
1213
|
+
"model": "anthropic/claude-haiku-4-20250514",
|
|
1214
|
+
"tools": {
|
|
1215
|
+
"write": false,
|
|
1216
|
+
"edit": false,
|
|
1217
|
+
"bash": false
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
"mcp_servers": {
|
|
1222
|
+
"parallel-ai": {
|
|
1223
|
+
"type": "stdio",
|
|
1224
|
+
"command": "npx",
|
|
1225
|
+
"args": ["-y", "@parallel-ai/mcp-server"],
|
|
1226
|
+
"env": {
|
|
1227
|
+
"API_KEY": "${env:PARALLEL_AI_TOKEN}"
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
"context7": {
|
|
1231
|
+
"type": "stdio",
|
|
1232
|
+
"command": "npx",
|
|
1233
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}, null, 2);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* Generate .opencode/agents/plan-review.md content
|
|
1241
|
+
*/
|
|
1242
|
+
function generateOpenCodePlanAgentContent() {
|
|
1243
|
+
return `---
|
|
1244
|
+
description: Read-only planning and analysis
|
|
1245
|
+
mode: subagent
|
|
1246
|
+
model: anthropic/claude-sonnet-4-20250514
|
|
1247
|
+
temperature: 0.1
|
|
1248
|
+
tools:
|
|
1249
|
+
write: false
|
|
1250
|
+
edit: false
|
|
1251
|
+
bash: false
|
|
1252
|
+
---
|
|
1253
|
+
|
|
1254
|
+
# Planning & Review Agent
|
|
1255
|
+
|
|
1256
|
+
You are in **planning mode** for the Forge 7-Stage TDD Workflow.
|
|
1257
|
+
|
|
1258
|
+
## Your Role
|
|
1259
|
+
|
|
1260
|
+
Focus on:
|
|
1261
|
+
- Understanding requirements thoroughly
|
|
1262
|
+
- Researching existing patterns in the codebase
|
|
1263
|
+
- Creating detailed implementation plans
|
|
1264
|
+
- Identifying test scenarios upfront
|
|
1265
|
+
- Analyzing OWASP Top 10 security considerations
|
|
1266
|
+
- **NO code changes allowed** - planning only
|
|
1267
|
+
|
|
1268
|
+
## Forge Planning Stages
|
|
1269
|
+
|
|
1270
|
+
### Stage 1: /plan
|
|
1271
|
+
- Research with web search for best practices
|
|
1272
|
+
- Document findings in \`docs/plans/<feature-slug>-design.md\`
|
|
1273
|
+
- Include security analysis (OWASP Top 10)
|
|
1274
|
+
- Create detailed plan in \`.claude/plans/<feature-slug>.md\`
|
|
1275
|
+
- Break down into TDD cycles (RED-GREEN-REFACTOR)
|
|
1276
|
+
- Identify files to create/modify
|
|
1277
|
+
|
|
1278
|
+
## Output Format
|
|
1279
|
+
|
|
1280
|
+
Your plan should include:
|
|
1281
|
+
1. **Requirements Summary** - What needs to be built
|
|
1282
|
+
2. **Test Scenarios** - All tests to write (RED phase)
|
|
1283
|
+
3. **Implementation Steps** - Minimal code to pass tests (GREEN phase)
|
|
1284
|
+
4. **Security Analysis** - OWASP Top 10 relevant risks
|
|
1285
|
+
5. **Files Affected** - List of files to create/modify
|
|
1286
|
+
6. **Verification** - How to test end-to-end
|
|
1287
|
+
|
|
1288
|
+
**Remember**: You are read-only. No code changes. Planning only.
|
|
1289
|
+
`;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
/**
|
|
1293
|
+
* Generate .opencode/agents/tdd-build.md content
|
|
1294
|
+
*/
|
|
1295
|
+
function generateOpenCodeBuildAgentContent() {
|
|
1296
|
+
return `---
|
|
1297
|
+
description: TDD implementation with full tools
|
|
1298
|
+
mode: primary
|
|
1299
|
+
model: anthropic/claude-sonnet-4-20250514
|
|
1300
|
+
temperature: 0
|
|
1301
|
+
tools:
|
|
1302
|
+
write: true
|
|
1303
|
+
edit: true
|
|
1304
|
+
bash: true
|
|
1305
|
+
---
|
|
1306
|
+
|
|
1307
|
+
# TDD Build Agent
|
|
1308
|
+
|
|
1309
|
+
You are in **implementation mode** for the Forge 7-Stage TDD Workflow.
|
|
1310
|
+
|
|
1311
|
+
## MANDATORY TDD Process
|
|
1312
|
+
|
|
1313
|
+
**RED-GREEN-REFACTOR** - No exceptions:
|
|
1314
|
+
|
|
1315
|
+
### RED Phase
|
|
1316
|
+
1. Write failing test FIRST
|
|
1317
|
+
2. Run test to confirm it fails for the right reason
|
|
1318
|
+
3. Commit: \`git commit -m "test: add [feature] tests (RED)"\`
|
|
1319
|
+
|
|
1320
|
+
### GREEN Phase
|
|
1321
|
+
1. Write minimal code to make the test pass
|
|
1322
|
+
2. Keep implementation simple
|
|
1323
|
+
3. Don't add features not covered by tests
|
|
1324
|
+
4. Commit: \`git commit -m "feat: implement [feature] (GREEN)"\`
|
|
1325
|
+
|
|
1326
|
+
### REFACTOR Phase
|
|
1327
|
+
1. Clean up code while keeping tests green
|
|
1328
|
+
2. Extract helpers, remove duplication
|
|
1329
|
+
3. Commit: \`git commit -m "refactor: [description]"\`
|
|
1330
|
+
|
|
1331
|
+
## Forge Development Stages
|
|
1332
|
+
|
|
1333
|
+
### Stage 2: /dev
|
|
1334
|
+
Implement features using TDD:
|
|
1335
|
+
- Follow RED-GREEN-REFACTOR for each feature
|
|
1336
|
+
- Commit after each GREEN cycle
|
|
1337
|
+
- Push regularly to remote
|
|
1338
|
+
|
|
1339
|
+
### Stage 3: /validate
|
|
1340
|
+
Validate before creating PR:
|
|
1341
|
+
- Type checking (TypeScript strict mode)
|
|
1342
|
+
- Linting (ESLint - no errors)
|
|
1343
|
+
- Security scanning (npm audit)
|
|
1344
|
+
- Test suite (all must pass)
|
|
1345
|
+
- Code coverage (80%+ required)
|
|
1346
|
+
|
|
1347
|
+
## Security
|
|
1348
|
+
|
|
1349
|
+
For every feature, check OWASP Top 10:
|
|
1350
|
+
- Input validation
|
|
1351
|
+
- Output sanitization
|
|
1352
|
+
- Authentication/Authorization
|
|
1353
|
+
- Cryptography
|
|
1354
|
+
- Dependency vulnerabilities
|
|
1355
|
+
|
|
1356
|
+
## Quality Standards
|
|
1357
|
+
|
|
1358
|
+
- Tests written BEFORE implementation
|
|
1359
|
+
- 80%+ code coverage
|
|
1360
|
+
- No ESLint errors
|
|
1361
|
+
- Security vulnerabilities addressed
|
|
1362
|
+
- Documentation updated progressively
|
|
1363
|
+
`;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Generate docs/ARCHITECTURE.md explaining Commands vs Skills vs MCP
|
|
1368
|
+
* @param {string} projectPath - Path to the project root
|
|
1369
|
+
* @param {Object} options - Generation options
|
|
1370
|
+
* @returns {Promise<void>}
|
|
1371
|
+
*/
|
|
1372
|
+
async function generateArchitectureDoc(projectPath, options = {}) {
|
|
1373
|
+
const { overwrite = false } = options;
|
|
1374
|
+
const docsDir = path.join(projectPath, 'docs');
|
|
1375
|
+
const architecturePath = path.join(docsDir, 'ARCHITECTURE.md');
|
|
1376
|
+
|
|
1377
|
+
// Check if file exists and overwrite is false
|
|
1378
|
+
if (fs.existsSync(architecturePath) && !overwrite) {
|
|
1379
|
+
return; // Skip generation
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// Ensure docs directory exists
|
|
1383
|
+
await fs.promises.mkdir(docsDir, { recursive: true });
|
|
1384
|
+
|
|
1385
|
+
const content = generateArchitectureContent();
|
|
1386
|
+
await fs.promises.writeFile(architecturePath, content, 'utf-8');
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Generate content for ARCHITECTURE.md
|
|
1391
|
+
* @returns {string}
|
|
1392
|
+
*/
|
|
1393
|
+
function generateArchitectureContent() {
|
|
1394
|
+
return `# Forge Architecture: How Multi-Agent Support Works
|
|
1395
|
+
|
|
1396
|
+
## Overview
|
|
1397
|
+
|
|
1398
|
+
Forge supports multiple AI agents through a three-tier architecture:
|
|
1399
|
+
|
|
1400
|
+
1. **Commands** - Universal workflow stages in AGENTS.md
|
|
1401
|
+
2. **Skills** - Agent-specific capabilities (Claude Code only)
|
|
1402
|
+
3. **MCP Servers** - Model Context Protocol for enhanced tools
|
|
1403
|
+
|
|
1404
|
+
## 1. Commands (Universal)
|
|
1405
|
+
|
|
1406
|
+
**What**: Workflow stages defined in AGENTS.md as markdown sections
|
|
1407
|
+
|
|
1408
|
+
**How it works**:
|
|
1409
|
+
- AI reads AGENTS.md and follows the documented workflow
|
|
1410
|
+
- Works with ANY agent that supports instruction files
|
|
1411
|
+
- Commands are just structured instructions, not executable code
|
|
1412
|
+
|
|
1413
|
+
**Examples**:
|
|
1414
|
+
- \`/status\` - Check current context and active work
|
|
1415
|
+
- \`/plan\` - Create implementation plan
|
|
1416
|
+
- \`/dev\` - TDD development
|
|
1417
|
+
- \`/validate\` - Run all validation checks
|
|
1418
|
+
|
|
1419
|
+
**Compatibility**: ✅ Universal (works with all agents)
|
|
1420
|
+
|
|
1421
|
+
## 2. Skills (Agent-Specific)
|
|
1422
|
+
|
|
1423
|
+
**What**: Executable integrations for specific agents
|
|
1424
|
+
|
|
1425
|
+
**How it works**:
|
|
1426
|
+
- Defined in agent-specific directories (e.g., \`.claude/skills/\`)
|
|
1427
|
+
- Agent loads skills and invokes them as tools
|
|
1428
|
+
- Skills can make API calls, run commands, etc.
|
|
1429
|
+
|
|
1430
|
+
**Examples**:
|
|
1431
|
+
- \`/parallel-ai\` - Web research via Parallel AI API
|
|
1432
|
+
- \`/sonarcloud\` - Code quality analysis
|
|
1433
|
+
- \`/context7\` - Library documentation lookup
|
|
1434
|
+
|
|
1435
|
+
**Compatibility**: ⚠️ Limited (only Claude Code currently supports)
|
|
1436
|
+
|
|
1437
|
+
## 3. MCP Servers (Model Context Protocol)
|
|
1438
|
+
|
|
1439
|
+
**What**: Standardized tool discovery via MCP protocol
|
|
1440
|
+
|
|
1441
|
+
**How it works**:
|
|
1442
|
+
- Defined in \`.mcp.json\` or agent-specific config
|
|
1443
|
+
- Agent auto-discovers tools at runtime
|
|
1444
|
+
- Servers provide capabilities dynamically
|
|
1445
|
+
|
|
1446
|
+
**Examples**:
|
|
1447
|
+
- \`context7\` - Up-to-date library documentation
|
|
1448
|
+
- \`parallel-ai\` - Web search and research
|
|
1449
|
+
- \`github\` - GitHub API integration
|
|
1450
|
+
|
|
1451
|
+
**Compatibility**: ✅ Growing (Claude Code, GitHub Copilot, Cursor, OpenCode support MCP)
|
|
1452
|
+
|
|
1453
|
+
## Universal vs Agent-Specific
|
|
1454
|
+
|
|
1455
|
+
### Universal Approach (AGENTS.md)
|
|
1456
|
+
|
|
1457
|
+
**Pros**:
|
|
1458
|
+
- Works with ALL agents (100% compatibility)
|
|
1459
|
+
- Single source of truth
|
|
1460
|
+
- Easy to maintain
|
|
1461
|
+
- No setup required
|
|
1462
|
+
|
|
1463
|
+
**Cons**:
|
|
1464
|
+
- Commands are instructions, not executable code
|
|
1465
|
+
- Agent must read and interpret manually
|
|
1466
|
+
|
|
1467
|
+
### Agent-Specific Approach (Skills/MCP)
|
|
1468
|
+
|
|
1469
|
+
**Pros**:
|
|
1470
|
+
- Executable tools and APIs
|
|
1471
|
+
- Automatic discovery (MCP)
|
|
1472
|
+
- Enhanced capabilities
|
|
1473
|
+
|
|
1474
|
+
**Cons**:
|
|
1475
|
+
- Limited agent support
|
|
1476
|
+
- Requires configuration
|
|
1477
|
+
- More complex setup
|
|
1478
|
+
|
|
1479
|
+
## Forge's Hybrid Strategy
|
|
1480
|
+
|
|
1481
|
+
Forge uses **both** approaches:
|
|
1482
|
+
|
|
1483
|
+
1. **AGENTS.md** - Baseline workflow for all agents
|
|
1484
|
+
2. **MCP Servers** - Enhanced tools (if agent supports)
|
|
1485
|
+
3. **Skills** - Fallback for agents without MCP
|
|
1486
|
+
|
|
1487
|
+
This ensures:
|
|
1488
|
+
- ✅ Universal compatibility (AGENTS.md)
|
|
1489
|
+
- ✅ Enhanced capabilities (MCP)
|
|
1490
|
+
- ✅ Gradual adoption (agents add MCP support over time)
|
|
1491
|
+
|
|
1492
|
+
## File Organization
|
|
1493
|
+
|
|
1494
|
+
\`\`\`
|
|
1495
|
+
project/
|
|
1496
|
+
├── AGENTS.md # Universal commands (all agents)
|
|
1497
|
+
├── .mcp.json # MCP servers (Claude, Copilot, Cursor, OpenCode)
|
|
1498
|
+
├── .claude/
|
|
1499
|
+
│ └── skills/ # Claude-specific skills
|
|
1500
|
+
├── .github/
|
|
1501
|
+
│ └── copilot-instructions.md # Copilot-specific instructions
|
|
1502
|
+
└── .cursor/
|
|
1503
|
+
└── rules/ # Cursor-specific rules
|
|
1504
|
+
\`\`\`
|
|
1505
|
+
|
|
1506
|
+
## For Developers
|
|
1507
|
+
|
|
1508
|
+
**When creating a new workflow stage:**
|
|
1509
|
+
|
|
1510
|
+
1. Document in AGENTS.md (required - universal)
|
|
1511
|
+
2. Add MCP server if enhanced capability needed (optional)
|
|
1512
|
+
3. Create skill for Claude Code if MCP not available (fallback)
|
|
1513
|
+
|
|
1514
|
+
**When choosing an agent:**
|
|
1515
|
+
|
|
1516
|
+
- All agents get full workflow via AGENTS.md
|
|
1517
|
+
- Agents with MCP get enhanced tools automatically
|
|
1518
|
+
- Claude Code gets additional skills
|
|
1519
|
+
|
|
1520
|
+
No coordination needed between agents - they all work independently.
|
|
1521
|
+
|
|
1522
|
+
## See Also
|
|
1523
|
+
|
|
1524
|
+
- [CONFIGURATION.md](./CONFIGURATION.md) - Solo vs Team setup
|
|
1525
|
+
- [MCP_SETUP.md](./MCP_SETUP.md) - MCP server configuration
|
|
1526
|
+
- [AGENTS.md](../AGENTS.md) - Universal agent instructions
|
|
1527
|
+
`;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* Generate docs/CONFIGURATION.md explaining Solo vs Team setup
|
|
1532
|
+
* @param {string} projectPath - Path to the project root
|
|
1533
|
+
* @param {Object} options - Generation options
|
|
1534
|
+
* @returns {Promise<void>}
|
|
1535
|
+
*/
|
|
1536
|
+
async function generateConfigurationDoc(projectPath, options = {}) {
|
|
1537
|
+
const { overwrite = false } = options;
|
|
1538
|
+
const docsDir = path.join(projectPath, 'docs');
|
|
1539
|
+
const configPath = path.join(docsDir, 'CONFIGURATION.md');
|
|
1540
|
+
|
|
1541
|
+
// Check if file exists and overwrite is false
|
|
1542
|
+
if (fs.existsSync(configPath) && !overwrite) {
|
|
1543
|
+
return; // Skip generation
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// Ensure docs directory exists
|
|
1547
|
+
await fs.promises.mkdir(docsDir, { recursive: true });
|
|
1548
|
+
|
|
1549
|
+
const content = generateConfigurationContent();
|
|
1550
|
+
await fs.promises.writeFile(configPath, content, 'utf-8');
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
/**
|
|
1554
|
+
* Generate content for CONFIGURATION.md
|
|
1555
|
+
* @returns {string}
|
|
1556
|
+
*/
|
|
1557
|
+
function generateConfigurationContent() {
|
|
1558
|
+
return `# Forge Configuration Guide
|
|
1559
|
+
|
|
1560
|
+
## Overview
|
|
1561
|
+
|
|
1562
|
+
Forge adapts to your workflow with two primary profiles:
|
|
1563
|
+
|
|
1564
|
+
- **Solo**: Individual developer, streamlined workflow
|
|
1565
|
+
- **Team**: Multiple contributors, enforced quality gates
|
|
1566
|
+
|
|
1567
|
+
## Configuration File
|
|
1568
|
+
|
|
1569
|
+
Create \`.forgerc.json\` in your project root:
|
|
1570
|
+
|
|
1571
|
+
\`\`\`json
|
|
1572
|
+
{
|
|
1573
|
+
"profile": "solo", // or "team"
|
|
1574
|
+
|
|
1575
|
+
"solo": {
|
|
1576
|
+
"branch_protection": "minimal",
|
|
1577
|
+
"required_reviewers": 0,
|
|
1578
|
+
"auto_merge": true,
|
|
1579
|
+
"commit_signing": "optional"
|
|
1580
|
+
},
|
|
1581
|
+
|
|
1582
|
+
"team": {
|
|
1583
|
+
"branch_protection": "strict",
|
|
1584
|
+
"required_reviewers": 1,
|
|
1585
|
+
"codeowners": "required",
|
|
1586
|
+
"commit_signing": "required",
|
|
1587
|
+
"auto_merge": false
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
\`\`\`
|
|
1591
|
+
|
|
1592
|
+
## Solo Profile
|
|
1593
|
+
|
|
1594
|
+
**Best for**: Individual developers, side projects, rapid prototyping
|
|
1595
|
+
|
|
1596
|
+
**Characteristics**:
|
|
1597
|
+
- Minimal branch protection (can push to main)
|
|
1598
|
+
- No review requirements
|
|
1599
|
+
- Auto-merge when checks pass
|
|
1600
|
+
- Optional commit signing
|
|
1601
|
+
- Faster iteration cycle
|
|
1602
|
+
|
|
1603
|
+
**Setup**:
|
|
1604
|
+
\`\`\`bash
|
|
1605
|
+
bunx forge setup --profile=solo
|
|
1606
|
+
\`\`\`
|
|
1607
|
+
|
|
1608
|
+
**Example workflow**:
|
|
1609
|
+
\`\`\`bash
|
|
1610
|
+
/plan feature-slug # Research, plan, branch
|
|
1611
|
+
/dev # Implement with TDD
|
|
1612
|
+
/validate # Run all checks
|
|
1613
|
+
git push # Direct push (no PR needed)
|
|
1614
|
+
\`\`\`
|
|
1615
|
+
|
|
1616
|
+
## Team Profile
|
|
1617
|
+
|
|
1618
|
+
**Best for**: Teams, open-source projects, production systems
|
|
1619
|
+
|
|
1620
|
+
**Characteristics**:
|
|
1621
|
+
- Strict branch protection (no direct push to main)
|
|
1622
|
+
- Required reviewers (1+ team members)
|
|
1623
|
+
- CODEOWNERS enforcement
|
|
1624
|
+
- Required commit signing
|
|
1625
|
+
- Manual merge after approval
|
|
1626
|
+
- Quality gates enforced
|
|
1627
|
+
|
|
1628
|
+
**Setup**:
|
|
1629
|
+
\`\`\`bash
|
|
1630
|
+
bunx forge setup --profile=team --interactive
|
|
1631
|
+
\`\`\`
|
|
1632
|
+
|
|
1633
|
+
**Example workflow**:
|
|
1634
|
+
\`\`\`bash
|
|
1635
|
+
/plan feature-slug # Research, plan, branch + worktree
|
|
1636
|
+
/dev # Implement with TDD
|
|
1637
|
+
/validate # Run all checks
|
|
1638
|
+
/ship # Create PR
|
|
1639
|
+
/review # Address feedback
|
|
1640
|
+
/premerge # Merge after approval
|
|
1641
|
+
\`\`\`
|
|
1642
|
+
|
|
1643
|
+
## Configuration Options
|
|
1644
|
+
|
|
1645
|
+
### Branch Protection
|
|
1646
|
+
|
|
1647
|
+
**Solo**: \`minimal\`
|
|
1648
|
+
- Allows direct push to main
|
|
1649
|
+
- No status checks required
|
|
1650
|
+
- Fast iteration
|
|
1651
|
+
|
|
1652
|
+
**Team**: \`strict\`
|
|
1653
|
+
- Blocks direct push to main/master
|
|
1654
|
+
- Requires PR approval
|
|
1655
|
+
- Status checks must pass
|
|
1656
|
+
- CODEOWNERS must approve
|
|
1657
|
+
|
|
1658
|
+
### Required Reviewers
|
|
1659
|
+
|
|
1660
|
+
**Solo**: \`0\`
|
|
1661
|
+
- No review needed
|
|
1662
|
+
- Self-merge allowed
|
|
1663
|
+
|
|
1664
|
+
**Team**: \`1\` (or more)
|
|
1665
|
+
- At least 1 approval required
|
|
1666
|
+
- CODEOWNERS approval for critical files
|
|
1667
|
+
|
|
1668
|
+
### Auto-Merge
|
|
1669
|
+
|
|
1670
|
+
**Solo**: \`true\`
|
|
1671
|
+
- PRs auto-merge when checks pass
|
|
1672
|
+
- Faster workflow
|
|
1673
|
+
|
|
1674
|
+
**Team**: \`false\`
|
|
1675
|
+
- Manual merge after review
|
|
1676
|
+
- Final approval step
|
|
1677
|
+
|
|
1678
|
+
### Commit Signing
|
|
1679
|
+
|
|
1680
|
+
**Solo**: \`optional\`
|
|
1681
|
+
- GPG signing recommended but not required
|
|
1682
|
+
|
|
1683
|
+
**Team**: \`required\`
|
|
1684
|
+
- All commits must be signed
|
|
1685
|
+
- Verified authorship
|
|
1686
|
+
|
|
1687
|
+
## Detection (Auto-Configuration)
|
|
1688
|
+
|
|
1689
|
+
Forge auto-detects your profile during setup:
|
|
1690
|
+
|
|
1691
|
+
**Solo indicators**:
|
|
1692
|
+
- Single contributor in git log
|
|
1693
|
+
- No CODEOWNERS file
|
|
1694
|
+
- No branch protection configured
|
|
1695
|
+
|
|
1696
|
+
**Team indicators**:
|
|
1697
|
+
- Multiple contributors
|
|
1698
|
+
- CODEOWNERS file exists
|
|
1699
|
+
- Branch protection already set up
|
|
1700
|
+
|
|
1701
|
+
Override auto-detection:
|
|
1702
|
+
\`\`\`bash
|
|
1703
|
+
bunx forge setup --profile=team # Force team profile
|
|
1704
|
+
\`\`\`
|
|
1705
|
+
|
|
1706
|
+
## Switching Profiles
|
|
1707
|
+
|
|
1708
|
+
Change profile anytime:
|
|
1709
|
+
|
|
1710
|
+
\`\`\`bash
|
|
1711
|
+
# Edit .forgerc.json
|
|
1712
|
+
{
|
|
1713
|
+
"profile": "team" // Change from "solo" to "team"
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
# Re-run setup
|
|
1717
|
+
bunx forge setup
|
|
1718
|
+
\`\`\`
|
|
1719
|
+
|
|
1720
|
+
Forge will update:
|
|
1721
|
+
- Branch protection rules
|
|
1722
|
+
- Git hooks (lefthook)
|
|
1723
|
+
- GitHub workflows
|
|
1724
|
+
- PR templates
|
|
1725
|
+
|
|
1726
|
+
## Custom Profiles
|
|
1727
|
+
|
|
1728
|
+
Create custom profiles for specific needs:
|
|
1729
|
+
|
|
1730
|
+
\`\`\`json
|
|
1731
|
+
{
|
|
1732
|
+
"profile": "custom-strict",
|
|
1733
|
+
|
|
1734
|
+
"custom-strict": {
|
|
1735
|
+
"branch_protection": "strict",
|
|
1736
|
+
"required_reviewers": 2,
|
|
1737
|
+
"codeowners": "required",
|
|
1738
|
+
"commit_signing": "required",
|
|
1739
|
+
"auto_merge": false,
|
|
1740
|
+
"quality_gates": {
|
|
1741
|
+
"coverage_threshold": 90,
|
|
1742
|
+
"mutation_score": 75
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
\`\`\`
|
|
1747
|
+
|
|
1748
|
+
## Environment-Specific Settings
|
|
1749
|
+
|
|
1750
|
+
Override for CI/CD:
|
|
1751
|
+
|
|
1752
|
+
\`\`\`bash
|
|
1753
|
+
# .forgerc.ci.json (for CI/CD environments)
|
|
1754
|
+
{
|
|
1755
|
+
"profile": "team",
|
|
1756
|
+
"ci": {
|
|
1757
|
+
"skip_interactive": true,
|
|
1758
|
+
"strict_checks": true
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
\`\`\`
|
|
1762
|
+
|
|
1763
|
+
Load with:
|
|
1764
|
+
\`\`\`bash
|
|
1765
|
+
bunx forge setup --config=.forgerc.ci.json
|
|
1766
|
+
\`\`\`
|
|
1767
|
+
|
|
1768
|
+
## See Also
|
|
1769
|
+
|
|
1770
|
+
- [ARCHITECTURE.md](./ARCHITECTURE.md) - How multi-agent support works
|
|
1771
|
+
- [MCP_SETUP.md](./MCP_SETUP.md) - MCP server configuration
|
|
1772
|
+
- [WORKFLOW.md](./WORKFLOW.md) - Complete workflow guide
|
|
1773
|
+
`;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* Generate docs/MCP_SETUP.md explaining MCP server configuration
|
|
1778
|
+
* @param {string} projectPath - Path to the project root
|
|
1779
|
+
* @param {Object} options - Generation options
|
|
1780
|
+
* @returns {Promise<void>}
|
|
1781
|
+
*/
|
|
1782
|
+
async function generateMcpSetupDoc(projectPath, options = {}) {
|
|
1783
|
+
const { overwrite = false } = options;
|
|
1784
|
+
const docsDir = path.join(projectPath, 'docs');
|
|
1785
|
+
const mcpPath = path.join(docsDir, 'MCP_SETUP.md');
|
|
1786
|
+
|
|
1787
|
+
// Check if file exists and overwrite is false
|
|
1788
|
+
if (fs.existsSync(mcpPath) && !overwrite) {
|
|
1789
|
+
return; // Skip generation
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
// Ensure docs directory exists
|
|
1793
|
+
await fs.promises.mkdir(docsDir, { recursive: true });
|
|
1794
|
+
|
|
1795
|
+
const content = generateMcpSetupContent();
|
|
1796
|
+
await fs.promises.writeFile(mcpPath, content, 'utf-8');
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Generate content for MCP_SETUP.md
|
|
1801
|
+
* @returns {string}
|
|
1802
|
+
*/
|
|
1803
|
+
function generateMcpSetupContent() {
|
|
1804
|
+
return `# MCP Server Setup Guide
|
|
1805
|
+
|
|
1806
|
+
## What is MCP?
|
|
1807
|
+
|
|
1808
|
+
**Model Context Protocol (MCP)** is a standardized protocol for AI agents to discover and use external tools at runtime.
|
|
1809
|
+
|
|
1810
|
+
**Benefits**:
|
|
1811
|
+
- Auto-discovery of tools (no manual configuration)
|
|
1812
|
+
- Works across multiple AI agents
|
|
1813
|
+
- Enhanced capabilities (web search, API access, etc.)
|
|
1814
|
+
|
|
1815
|
+
**Supported Agents**:
|
|
1816
|
+
- ✅ Claude Code
|
|
1817
|
+
- ✅ GitHub Copilot (VS Code extension)
|
|
1818
|
+
- ✅ Cursor
|
|
1819
|
+
- ✅ OpenCode
|
|
1820
|
+
|
|
1821
|
+
## Quick Start
|
|
1822
|
+
|
|
1823
|
+
### 1. Install MCP-Compatible Agent
|
|
1824
|
+
|
|
1825
|
+
Choose one of the supported agents above.
|
|
1826
|
+
|
|
1827
|
+
### 2. Configure MCP Servers
|
|
1828
|
+
|
|
1829
|
+
Each agent has a different configuration location:
|
|
1830
|
+
|
|
1831
|
+
**Claude Code**: \`.mcp.json\` in project root
|
|
1832
|
+
**GitHub Copilot**: \`.mcp.json\` in project root (VS Code)
|
|
1833
|
+
**Cursor**: \`.cursor/mcp.json\`
|
|
1834
|
+
**OpenCode**: \`opencode.json\` under \`mcp_servers\`
|
|
1835
|
+
|
|
1836
|
+
### 3. Add Forge-Recommended Servers
|
|
1837
|
+
|
|
1838
|
+
Copy the configuration for your agent from the examples below.
|
|
1839
|
+
|
|
1840
|
+
## Recommended MCP Servers
|
|
1841
|
+
|
|
1842
|
+
### parallel-ai (Web Search & Research)
|
|
1843
|
+
|
|
1844
|
+
**Purpose**: Deep research with web search, data extraction, and analysis
|
|
1845
|
+
|
|
1846
|
+
**Setup for Claude Code**:
|
|
1847
|
+
\`\`\`json
|
|
1848
|
+
{
|
|
1849
|
+
"mcpServers": {
|
|
1850
|
+
"parallel-ai": {
|
|
1851
|
+
"command": "npx",
|
|
1852
|
+
"args": ["-y", "@parallel-ai/mcp-server"],
|
|
1853
|
+
"env": {
|
|
1854
|
+
"PARALLEL_AI_TOKEN": "\${env:PARALLEL_AI_TOKEN}"
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
\`\`\`
|
|
1860
|
+
|
|
1861
|
+
**Get API Token**: Sign up at [parallel.ai](https://parallel.ai)
|
|
1862
|
+
|
|
1863
|
+
**Usage in Forge**:
|
|
1864
|
+
- \`/plan <feature-name>\` - Research phase uses parallel-ai for web search
|
|
1865
|
+
|
|
1866
|
+
### context7 (Library Documentation)
|
|
1867
|
+
|
|
1868
|
+
**Purpose**: Up-to-date documentation for popular libraries and frameworks
|
|
1869
|
+
|
|
1870
|
+
**Setup for Claude Code**:
|
|
1871
|
+
\`\`\`json
|
|
1872
|
+
{
|
|
1873
|
+
"mcpServers": {
|
|
1874
|
+
"context7": {
|
|
1875
|
+
"command": "npx",
|
|
1876
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
\`\`\`
|
|
1881
|
+
|
|
1882
|
+
**No API key required** - Works out of the box
|
|
1883
|
+
|
|
1884
|
+
**Usage in Forge**:
|
|
1885
|
+
- Ask: "What's the latest React hooks API?"
|
|
1886
|
+
- Ask: "How do I use TypeScript generics?"
|
|
1887
|
+
|
|
1888
|
+
### github (GitHub API)
|
|
1889
|
+
|
|
1890
|
+
**Purpose**: GitHub repository access, issues, PRs, code search
|
|
1891
|
+
|
|
1892
|
+
**Setup for GitHub Copilot** (built-in):
|
|
1893
|
+
- No configuration needed, included by default in VS Code extension
|
|
1894
|
+
|
|
1895
|
+
**Setup for Claude Code**:
|
|
1896
|
+
\`\`\`json
|
|
1897
|
+
{
|
|
1898
|
+
"mcpServers": {
|
|
1899
|
+
"github": {
|
|
1900
|
+
"command": "npx",
|
|
1901
|
+
"args": ["-y", "@modelcontextprotocol/server-github"],
|
|
1902
|
+
"env": {
|
|
1903
|
+
"GITHUB_TOKEN": "\${env:GITHUB_TOKEN}"
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
\`\`\`
|
|
1909
|
+
|
|
1910
|
+
**Get Token**: Create personal access token at [github.com/settings/tokens](https://github.com/settings/tokens)
|
|
1911
|
+
|
|
1912
|
+
**Usage in Forge**:
|
|
1913
|
+
- \`/ship\` - Automatically uses GitHub API to create PR
|
|
1914
|
+
- \`/review\` - Fetches PR comments and feedback
|
|
1915
|
+
|
|
1916
|
+
## Agent-Specific Configuration
|
|
1917
|
+
|
|
1918
|
+
### Claude Code
|
|
1919
|
+
|
|
1920
|
+
**File**: \`.mcp.json\` in project root
|
|
1921
|
+
|
|
1922
|
+
**Example**:
|
|
1923
|
+
\`\`\`json
|
|
1924
|
+
{
|
|
1925
|
+
"mcpServers": {
|
|
1926
|
+
"parallel-ai": {
|
|
1927
|
+
"command": "npx",
|
|
1928
|
+
"args": ["-y", "@parallel-ai/mcp-server"],
|
|
1929
|
+
"env": {
|
|
1930
|
+
"PARALLEL_AI_TOKEN": "\${env:PARALLEL_AI_TOKEN}"
|
|
1931
|
+
}
|
|
1932
|
+
},
|
|
1933
|
+
"context7": {
|
|
1934
|
+
"command": "npx",
|
|
1935
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
\`\`\`
|
|
1940
|
+
|
|
1941
|
+
**Environment Variables**: Set in \`.env\` or shell profile
|
|
1942
|
+
|
|
1943
|
+
### GitHub Copilot
|
|
1944
|
+
|
|
1945
|
+
**File**: \`.mcp.json\` in project root (VS Code)
|
|
1946
|
+
|
|
1947
|
+
**Example**:
|
|
1948
|
+
\`\`\`json
|
|
1949
|
+
{
|
|
1950
|
+
"mcpServers": {
|
|
1951
|
+
"context7": {
|
|
1952
|
+
"type": "local",
|
|
1953
|
+
"command": "npx",
|
|
1954
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
\`\`\`
|
|
1959
|
+
|
|
1960
|
+
**Note**: GitHub MCP server is built-in, no config needed
|
|
1961
|
+
|
|
1962
|
+
### Cursor
|
|
1963
|
+
|
|
1964
|
+
**File**: \`.cursor/mcp.json\`
|
|
1965
|
+
|
|
1966
|
+
**Example**:
|
|
1967
|
+
\`\`\`json
|
|
1968
|
+
{
|
|
1969
|
+
"mcpServers": {
|
|
1970
|
+
"parallel-ai": {
|
|
1971
|
+
"type": "http",
|
|
1972
|
+
"url": "https://api.parallel-ai.com/mcp",
|
|
1973
|
+
"headers": {
|
|
1974
|
+
"Authorization": "Bearer \${env:PARALLEL_AI_TOKEN}"
|
|
1975
|
+
}
|
|
1976
|
+
},
|
|
1977
|
+
"context7": {
|
|
1978
|
+
"type": "stdio",
|
|
1979
|
+
"command": "npx",
|
|
1980
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
\`\`\`
|
|
1985
|
+
|
|
1986
|
+
**Note**: Cursor supports both STDIO and HTTP MCP servers
|
|
1987
|
+
|
|
1988
|
+
### OpenCode
|
|
1989
|
+
|
|
1990
|
+
**File**: \`opencode.json\` (add under \`mcp_servers\`)
|
|
1991
|
+
|
|
1992
|
+
**Example**:
|
|
1993
|
+
\`\`\`json
|
|
1994
|
+
{
|
|
1995
|
+
"mcp_servers": {
|
|
1996
|
+
"parallel-ai": {
|
|
1997
|
+
"type": "stdio",
|
|
1998
|
+
"command": "npx",
|
|
1999
|
+
"args": ["-y", "@parallel-ai/mcp-server"],
|
|
2000
|
+
"env": {
|
|
2001
|
+
"API_KEY": "\${env:PARALLEL_AI_TOKEN}"
|
|
2002
|
+
}
|
|
2003
|
+
},
|
|
2004
|
+
"context7": {
|
|
2005
|
+
"type": "stdio",
|
|
2006
|
+
"command": "npx",
|
|
2007
|
+
"args": ["-y", "@context7/mcp-server"]
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
\`\`\`
|
|
2012
|
+
|
|
2013
|
+
## Setup with Forge
|
|
2014
|
+
|
|
2015
|
+
Forge can automatically configure MCP servers during setup:
|
|
2016
|
+
|
|
2017
|
+
\`\`\`bash
|
|
2018
|
+
# Auto-detect agent and configure MCP
|
|
2019
|
+
bunx forge setup --mcp
|
|
2020
|
+
|
|
2021
|
+
# Agent-specific setup with MCP
|
|
2022
|
+
bunx forge setup --agent=claude --mcp
|
|
2023
|
+
bunx forge setup --agent=copilot --mcp
|
|
2024
|
+
bunx forge setup --agent=cursor --mcp
|
|
2025
|
+
\`\`\`
|
|
2026
|
+
|
|
2027
|
+
This will:
|
|
2028
|
+
1. Detect installed agents
|
|
2029
|
+
2. Create appropriate MCP config files
|
|
2030
|
+
3. Add recommended servers (parallel-ai, context7)
|
|
2031
|
+
4. Set up environment variable placeholders
|
|
2032
|
+
|
|
2033
|
+
## Environment Variables
|
|
2034
|
+
|
|
2035
|
+
Create \`.env\` file in project root:
|
|
2036
|
+
|
|
2037
|
+
\`\`\`bash
|
|
2038
|
+
# .env (don't commit this file!)
|
|
2039
|
+
PARALLEL_AI_TOKEN=your_token_here
|
|
2040
|
+
GITHUB_TOKEN=your_github_token_here
|
|
2041
|
+
\`\`\`
|
|
2042
|
+
|
|
2043
|
+
Add to \`.gitignore\`:
|
|
2044
|
+
\`\`\`
|
|
2045
|
+
.env
|
|
2046
|
+
\`\`\`
|
|
2047
|
+
|
|
2048
|
+
## Verification
|
|
2049
|
+
|
|
2050
|
+
Test MCP setup:
|
|
2051
|
+
|
|
2052
|
+
**Claude Code**:
|
|
2053
|
+
\`\`\`bash
|
|
2054
|
+
# Ask Claude: "Search the web for best React testing practices"
|
|
2055
|
+
# Should use parallel-ai automatically
|
|
2056
|
+
\`\`\`
|
|
2057
|
+
|
|
2058
|
+
**GitHub Copilot**:
|
|
2059
|
+
\`\`\`bash
|
|
2060
|
+
# In VS Code, ask Copilot: "What's the latest TypeScript syntax?"
|
|
2061
|
+
# Should fetch from context7
|
|
2062
|
+
\`\`\`
|
|
2063
|
+
|
|
2064
|
+
**Cursor**:
|
|
2065
|
+
\`\`\`bash
|
|
2066
|
+
# In Cursor, use Agent mode: "Research authentication best practices"
|
|
2067
|
+
# Should use parallel-ai if configured
|
|
2068
|
+
\`\`\`
|
|
2069
|
+
|
|
2070
|
+
## Troubleshooting
|
|
2071
|
+
|
|
2072
|
+
### MCP server not found
|
|
2073
|
+
|
|
2074
|
+
**Error**: "MCP server 'parallel-ai' not found"
|
|
2075
|
+
|
|
2076
|
+
**Solution**: Install server globally or ensure npx is working:
|
|
2077
|
+
\`\`\`bash
|
|
2078
|
+
npm install -g @parallel-ai/mcp-server
|
|
2079
|
+
\`\`\`
|
|
2080
|
+
|
|
2081
|
+
### Environment variables not loading
|
|
2082
|
+
|
|
2083
|
+
**Error**: "PARALLEL_AI_TOKEN not found"
|
|
2084
|
+
|
|
2085
|
+
**Solution**: Ensure \`.env\` is in project root and agent is restarted
|
|
2086
|
+
|
|
2087
|
+
### STDIO vs HTTP servers
|
|
2088
|
+
|
|
2089
|
+
**STDIO**: Runs as local process (e.g., \`npx @context7/mcp-server\`)
|
|
2090
|
+
**HTTP**: Calls remote API (e.g., \`https://api.parallel-ai.com/mcp\`)
|
|
2091
|
+
|
|
2092
|
+
Choose based on server documentation.
|
|
2093
|
+
|
|
2094
|
+
## See Also
|
|
2095
|
+
|
|
2096
|
+
- [ARCHITECTURE.md](./ARCHITECTURE.md) - How MCP fits in Forge architecture
|
|
2097
|
+
- [CONFIGURATION.md](./CONFIGURATION.md) - Solo vs Team setup
|
|
2098
|
+
- [MCP Protocol Spec](https://modelcontextprotocol.io) - Official MCP documentation
|
|
2099
|
+
`;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
module.exports = {
|
|
2103
|
+
detectProjectMetadata,
|
|
2104
|
+
generateAgentsMd,
|
|
2105
|
+
generateCopilotConfig,
|
|
2106
|
+
generateCursorConfig,
|
|
2107
|
+
generateKiloConfig,
|
|
2108
|
+
generateOpenCodeConfig,
|
|
2109
|
+
generateArchitectureDoc,
|
|
2110
|
+
generateConfigurationDoc,
|
|
2111
|
+
generateMcpSetupDoc
|
|
2112
|
+
};
|