BMAD-METHOD/workspace-utils/docs/github-copilot.md

388 lines
11 KiB
Markdown

# BMAD Workspace Integration - GitHub Copilot
## Overview
BMAD workspace utilities integrate seamlessly with GitHub Copilot in VS Code, providing enhanced AI-assisted development with intelligent context sharing and collaborative workspace management.
## Setup
### 1. Prerequisites
- VS Code with GitHub Copilot extension installed
- GitHub Copilot subscription active
- BMAD project initialized
### 2. Initialize Workspace
```bash
npm run workspace-init
```
This creates:
- Copilot-aware session tracking
- AI context files optimized for Copilot suggestions
- Integration with VS Code's workspace settings
### 3. Verify Integration
```bash
npm run workspace-status
```
Should show:
- ✅ Active session detected (github-copilot)
- 🤖 AI assistance integration enabled
- 📁 Copilot context files prepared
## GitHub Copilot Integration Features
### 🤖 AI-Enhanced Development
- **Context-Aware Suggestions**: Workspace context informs Copilot suggestions
- **Multi-File Understanding**: Copilot can reference workspace context across files
- **Collaborative AI**: Workspace tracks AI-assisted code for team visibility
- **Quality Integration**: AI suggestions tracked through workspace quality metrics
### 🧠 Intelligent Context Management
#### Copilot-Optimized Commands
```bash
npm run workspace-init # Creates Copilot-aware session
npm run workspace-status # Shows AI assistance metrics
npm run workspace-sync # Updates context for better Copilot suggestions
npm run workspace-health # Includes AI code quality checks
```
#### AI Context Files
```bash
# Context files optimized for Copilot
.workspace/context/copilot-context.md # Current development context
.workspace/context/code-patterns.md # Established code patterns
.workspace/context/ai-decisions.md # AI-assisted decisions
.workspace/quality/ai-metrics.json # AI code quality tracking
```
## VS Code + Copilot Integration Patterns
### 1. Enhanced Code Completion
The workspace provides context that improves Copilot suggestions:
```javascript
// File: .workspace/context/copilot-context.md
# Current Development Context
## Project Patterns
- Using TypeScript with strict mode
- React functional components with hooks
- Jest for testing with custom matchers
- Error handling with custom error classes
## Current Feature: User Authentication
- Implementing OAuth 2.0 flow
- Using JWT tokens for session management
- Validating with Zod schemas
- Following existing AuthService patterns
```
When Copilot sees this context, it generates more relevant suggestions that match your project patterns.
### 2. AI-Assisted Agent Handoffs
```bash
# Handoff work with AI context
npm run workspace-handoff create --to dev --work "Copilot helped implement auth flow" --notes "AI suggested OAuth patterns, validated with team standards"
# Track AI-assisted development
npm run workspace-sync # Updates AI metrics and context
```
### 3. Quality Tracking for AI Code
```bash
# Monitor AI-generated code quality
npm run workspace-health # Includes AI code metrics
# Sample health report for AI code:
# - Copilot suggestion acceptance rate: 85%
# - AI-generated code coverage: 92%
# - Pattern consistency with existing code: 94%
```
## Best Practices for Copilot Users
### 🚀 Starting AI-Assisted Development
#### 1. Initialize Context
```bash
# Start workspace
npm run workspace-init
# Update context for Copilot
npm run workspace-sync
```
#### 2. Prepare Context Files
Create `.workspace/context/copilot-context.md`:
```markdown
# Development Context for Copilot
## Current Sprint Goals
- Implement user authentication system
- Add data validation layer
- Create responsive dashboard UI
## Code Standards
- TypeScript strict mode
- Functional React components
- Comprehensive error handling
- 90%+ test coverage requirement
## Architecture Patterns
- Clean Architecture with dependency injection
- Repository pattern for data access
- Command/Query separation
- Event-driven updates
```
### 🔧 During Development
#### Optimizing Copilot Suggestions
1. **Keep context updated**: Add relevant information to workspace context files
2. **Reference patterns**: Maintain `.workspace/context/code-patterns.md` with examples
3. **Track decisions**: Document AI-suggested approaches in `.workspace/decisions/`
#### Context-Driven Development
```bash
# Before major feature work
npm run workspace-sync # Ensures Copilot has latest context
# After Copilot generates significant code
npm run workspace-handoff create --notes "Copilot implemented OAuth flow"
# Regular quality checks
npm run workspace-health # Monitor AI code quality
```
### 📊 AI Code Quality Management
#### Tracking AI Contributions
The workspace system tracks:
- **AI Suggestion Acceptance Rate**: How often you accept Copilot suggestions
- **Code Quality Metrics**: Quality of AI-generated vs human-written code
- **Pattern Consistency**: How well AI code matches project patterns
- **Test Coverage**: Coverage of AI-generated code vs requirements
```bash
# View AI metrics
npm run workspace-health --ai-focus
# Sample output:
# 🤖 AI Code Metrics:
# • Suggestion acceptance: 78%
# • Quality score: 92/100
# • Pattern consistency: 89%
# • Test coverage: 85%
```
## VS Code Workspace Configuration
### 1. Workspace Settings
Add to `.vscode/settings.json`:
```json
{
"github.copilot.enable": {
"*": true,
"yaml": false,
"plaintext": false
},
"github.copilot.advanced": {
"secret_key": "github-copilot-bmad-workspace",
"length": 500,
"temperature": 0.1
},
"bmad.workspace.integration": true,
"bmad.workspace.contextFiles": [
".workspace/context/copilot-context.md",
".workspace/context/code-patterns.md"
]
}
```
### 2. Tasks Integration
Add to `.vscode/tasks.json`:
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "BMAD: Workspace Init",
"type": "shell",
"command": "npm run workspace-init",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "BMAD: Sync Context for Copilot",
"type": "shell",
"command": "npm run workspace-sync",
"group": "build"
},
{
"label": "BMAD: AI Health Check",
"type": "shell",
"command": "npm run workspace-health --ai-focus",
"group": "test",
"presentation": {
"reveal": "always"
}
}
]
}
```
### 3. Keybindings
Add to `.vscode/keybindings.json`:
```json
[
{
"key": "ctrl+shift+w ctrl+shift+i",
"command": "workbench.action.tasks.runTask",
"args": "BMAD: Workspace Init"
},
{
"key": "ctrl+shift+w ctrl+shift+s",
"command": "workbench.action.tasks.runTask",
"args": "BMAD: Sync Context for Copilot"
},
{
"key": "ctrl+shift+w ctrl+shift+h",
"command": "workbench.action.tasks.runTask",
"args": "BMAD: AI Health Check"
}
]
```
## Advanced Copilot Integration
### 1. Context-Aware Prompts
Use workspace context to improve Copilot prompts:
```javascript
// Example: Using workspace context in comments for better suggestions
// Based on .workspace/context/auth-patterns.md, implement OAuth login
// Following the AuthService pattern established in the workspace
// Include error handling as defined in .workspace/context/error-patterns.md
function loginWithOAuth(provider) {
// Copilot will generate code matching your established patterns
}
```
### 2. AI Decision Tracking
```bash
# Track AI-suggested architectural decisions
npm run workspace-handoff create --to architect --work "Review Copilot-suggested auth architecture" --notes "AI suggested JWT with refresh tokens, need validation"
```
### 3. Quality Gates for AI Code
```bash
# Set up quality gates that include AI metrics
npm run workspace-health --exit-code # Fails CI if AI code quality below threshold
```
## Troubleshooting
### Common Issues
**"Copilot not using workspace context"**
- Ensure context files are in `.workspace/context/`
- Update context with `npm run workspace-sync`
- Restart VS Code to refresh Copilot context
**"Poor quality AI suggestions"**
- Check workspace context is current: `npm run workspace-status`
- Update code patterns: Edit `.workspace/context/code-patterns.md`
- Verify session tracking: Should show `github-copilot` IDE type
**"AI metrics not tracking"**
- Initialize workspace: `npm run workspace-init`
- Check health status: `npm run workspace-health`
- Verify VS Code workspace settings include BMAD integration
### Copilot-Specific Issues
**"Suggestions don't match project patterns"**
- Update `.workspace/context/copilot-context.md` with current patterns
- Add examples to `.workspace/context/code-patterns.md`
- Sync context: `npm run workspace-sync`
**"AI quality scores are low"**
- Review Copilot suggestion acceptance rate
- Update context files with better examples
- Consider adjusting Copilot temperature in VS Code settings
## Performance Optimization
### Context File Management
```bash
# Keep context files optimized for Copilot
npm run workspace-cleanup --ai-optimize
# Compress large context files
npm run workspace-sync --compress
```
### Selective AI Context
Only include relevant context for current work:
```markdown
<!-- .workspace/context/copilot-context.md -->
# Current Focus: Authentication Module
## Relevant Patterns (for this sprint only)
- OAuth 2.0 implementation patterns
- JWT token validation
- Error handling for auth failures
## Not Currently Relevant
<!-- Keep other patterns commented until needed -->
<!-- - Payment processing patterns -->
<!-- - Data visualization patterns -->
```
## Integration Examples
### Example 1: Feature Development with AI Assistance
```bash
# 1. Initialize workspace
npm run workspace-init
# 2. Prepare context for new feature
echo "Implementing user profile management with Copilot assistance" > .workspace/context/current-work.md
# 3. Sync context for Copilot
npm run workspace-sync
# 4. Develop with Copilot
# (VS Code: Copilot uses workspace context for better suggestions)
# 5. Track AI contribution
npm run workspace-handoff create --work "Profile management with AI assistance" --notes "Copilot suggested efficient CRUD patterns"
# 6. Quality check
npm run workspace-health --ai-focus
```
### Example 2: AI-Assisted Code Review
```bash
# 1. After development phase
npm run workspace-sync # Update context with recent changes
# 2. Create review handoff
npm run workspace-handoff create --to qa --work "Review AI-assisted profile implementation"
# 3. QA checks AI code quality
npm run workspace-health # Shows AI code metrics
# 4. Address any quality issues
# (Use workspace context to improve code consistency)
```
---
*This guide optimizes GitHub Copilot integration with BMAD workspace for enhanced AI-assisted development. The workspace system provides context that improves AI suggestions while maintaining team collaboration and code quality.*