-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Pair Programming System
The Pair Programming System in Claude-Flow enables collaborative development between human developers and AI agents with real-time verification, continuous validation, and automated quality enforcement. It implements a "verification-first" approach where every change is validated against truth thresholds before acceptance.
- 🔍 Real-time Verification: Every code change is instantly verified
- 🎯 Truth Enforcement: Maintains 95% truth accuracy threshold
- 🔄 Auto-rollback: Automatic recovery from verification failures
- 👥 Collaborative Intelligence: Human creativity + AI verification
- 📊 Continuous Monitoring: Real-time quality metrics and feedback
- 🛡️ Byzantine Fault Tolerance: Protection against incorrect changes
┌─────────────────────────────────────────────────────────────┐
│ Pair Programming System │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Human │ │ AI │ │ Verification │ │
│ │ Developer │←→│ Agent │←→│ Engine │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ↓ ↓ ↓ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Continuous Integration Pipeline │ │
│ └────────────────────────────────────────────────────┘ │
│ ↓ ↓ ↓ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ File Watch │ │ Testing │ │ Rollback │ │
│ │ System │ │ Framework │ │ Manager │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
# Initialize project with Pair Programming enabled (local version)
./claude-flow init --pair
# Initialize with both verification and pair programming
./claude-flow init --verify --pair
# After npm publish, will be available as:
npx claude-flow@alpha init --verify --pair
# Force overwrite existing configuration
npx claude-flow@alpha init --verify --pair --force
This creates a specialized CLAUDE.md
configuration with:
- Pair Programming mode pre-configured
- Manual verification control (no auto-spam)
- Interactive session with readline interface
- Truth threshold set to 0.95
- Smart verification with weighted scoring
Start a pair programming session:
# Basic interactive session
npx claude-flow@alpha pair --start
# With manual verification
npx claude-flow@alpha pair --start --verify
# With automatic verification (60s cooldown)
npx claude-flow@alpha pair --start --verify --auto
# With testing enabled
npx claude-flow@alpha pair --start --test
# Set custom verification threshold
npx claude-flow@alpha pair --threshold 0.95
# Enable verification (manual by default)
npx claude-flow@alpha pair --verify
# Enable automatic verification with cooldown
npx claude-flow@alpha pair --verify --auto
# Set programming mode
npx claude-flow@alpha pair --mode <driver|navigator|switch>
# Run in background
npx claude-flow@alpha pair --start --background
npx claude-flow@alpha pair --mode strict
- Truth threshold: 0.95
- Auto-rollback: Enabled
- All checks: Required
- Real-time validation: Enabled
npx claude-flow@alpha pair --mode standard
- Truth threshold: 0.85
- Auto-rollback: Optional
- Core checks: Required
- Real-time validation: Enabled
npx claude-flow@alpha pair --mode development
- Truth threshold: 0.75
- Auto-rollback: Disabled
- Basic checks: Required
- Real-time validation: Optional
Developer: npx claude-flow@alpha pair --start --verify
System: ✅ Interactive session started
✅ Verification ready (manual mode)
✅ Session commands available
✅ Readline interface active
💻 pair> /help # Shows available commands
# During session, use these commands:
/verify - Run verification manually
/test - Execute test suite
/status - Show session status
/metrics - Display quality history
/auto - Toggle auto-verification
/switch - Change driver/navigator role
/suggest - Get AI suggestions
/commit - Pre-commit verification
/end - Exit session
// Manual verification (recommended)
onCommand('/verify') {
if (!isVerifying) {
results = await runWeightedChecks({
typeCheck: 0.4, // Most important
linting: 0.3, // Code quality
build: 0.3 // Compilation
});
// Intelligent scoring based on error count
score = calculateGraduatedScore(results);
displayResults(score);
}
}
// Optional auto-verification with cooldown
if (autoVerify && timeSinceLastCheck > 60000) {
await runVerification();
}
const codeChecks = {
typeCheck: {
weight: 0.40, // Increased weight for type safety
command: 'npm run typecheck',
required: true
},
linting: {
weight: 0.30,
command: 'npm run lint',
required: true
},
build: {
weight: 0.30,
command: 'npm run build',
required: true
}
};
// Intelligent scoring algorithm
function calculateScore(output) {
if (output.includes('error')) {
const errorCount = (output.match(/error/gi) || []).length;
return Math.max(0.2, 1.0 - (errorCount * 0.1));
} else if (output.includes('warning')) {
const warningCount = (output.match(/warning/gi) || []).length;
return Math.max(0.7, 1.0 - (warningCount * 0.05));
}
return 1.0;
}
const performanceChecks = {
buildTime: {
threshold: 30000, // 30 seconds
weight: 0.15
},
bundleSize: {
threshold: 5000000, // 5MB
weight: 0.10
},
testDuration: {
threshold: 60000, // 60 seconds
weight: 0.10
}
};
The AI agent provides:
- Syntax validation: Immediate syntax error detection
- Best practices: Suggests idiomatic code patterns
- Security analysis: Identifies potential vulnerabilities
- Performance optimization: Suggests efficiency improvements
- Documentation: Generates inline comments and docs
// Example AI suggestion
Developer: writes function without error handling
AI Agent: "Consider adding error handling:
```javascript
try {
const result = await apiCall();
return result;
} catch (error) {
logger.error('API call failed:', error);
throw new ApiError('Failed to fetch data', error);
}
```"
Verification: ✅ Score improved from 0.82 to 0.96
// .vscode/settings.json
{
"claude-flow.pair": {
"enabled": true,
"autoStart": true,
"threshold": 0.95,
"mode": "strict"
}
}
# .git/hooks/pre-commit
#!/bin/bash
npx claude-flow@alpha pair --verify --threshold 0.95
# .github/workflows/pair-verification.yml
name: Pair Programming Verification
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Pair Verification
run: |
npx claude-flow@alpha pair --verify
npx claude-flow@alpha truth --threshold 0.95
💻 pair> /status
📊 Session Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Session ID: pair_1755038032183
Duration: 45 minutes
Current Role: DRIVER
Mode: switch
Auto-Verify: Disabled
Last Verification: 0.82 (14:23:45)
💻 pair> /metrics
📈 Quality Metrics
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Verification History:
1. ████████████████ 0.82 - 14:20:00
2. ██████████████████ 0.91 - 14:22:30
3. ████████████ 0.65 - 14:23:45
4. ████████████████████ 0.98 - 14:25:15
Average: 0.84
Test Results:
1. ✅ 14:21:00
2. ❌ 14:23:00
3. ✅ 14:25:00
Success Rate: 67%
# Check current status
/status
# View quality metrics
/metrics
# Toggle auto-verification
/auto
# Run manual verification
/verify
# Run tests
/test
The system learns from your coding patterns:
const patterns = {
errorHandling: learnPattern('error-handling'),
naming: learnPattern('variable-naming'),
structure: learnPattern('code-structure')
};
// Applied during verification
verification.applyLearnedPatterns(patterns);
# Enable multiple specialized agents
npx claude-flow@alpha pair --agents "coder,reviewer,tester"
# Each agent focuses on specific aspects:
# - Coder: Implementation quality
# - Reviewer: Code review and standards
# - Tester: Test coverage and quality
// System maintains context across files
const context = {
project: analyzeProject(),
dependencies: analyzeDependencies(),
architecture: analyzeArchitecture(),
history: analyzeGitHistory()
};
// Context-aware suggestions
suggestions = generateSuggestions(change, context);
Begin pair programming at the start of your work:
# Morning routine
cd my-project
npx claude-flow@alpha pair --start --mode strict
Make small, verifiable changes:
// Good: Single responsibility
function validateEmail(email) {
return EMAIL_REGEX.test(email);
}
// Avoid: Multiple responsibilities in one change
function validateAndSaveUser(userData) {
// Too many changes for single verification
}
# Always check why verification failed
npx claude-flow@alpha truth --analyze
# Understand patterns
npx claude-flow@alpha pair --report
# Solution: Use manual verification
npx claude-flow@alpha pair --start --verify
# Use /verify command when needed
# If auto-verify is needed, it has 60s cooldown
npx claude-flow@alpha pair --start --verify --auto
# Check specific issues
/verify # See which checks fail
# Common fixes:
npm run typecheck # Fix TypeScript errors
npm run lint --fix # Auto-fix linting
npm run build # Check compilation
# End current session
npx claude-flow@alpha pair --end
# Check for active sessions
npx claude-flow@alpha pair --status
# Start fresh
npx claude-flow@alpha pair --start
# Use manual verification only
npx claude-flow@alpha pair --start --verify
# Don't use --auto flag
# Check metrics to identify patterns
/metrics # During session
The Pair Programming system now integrates with the verification-training system for continuous improvement:
- Every pair session generates verification data
- Verification results feed the training system
- System learns which patterns lead to success
- Future sessions benefit from improved predictions
# Start pair programming with verification
./claude-flow pair --start
# After session, feed results to training
./claude-flow verify-train feed
# Check improvement over time
./claude-flow verify-train status
# Get predictions for next session
./claude-flow verify-train predict default coder
- Agent reliability improves with each session
- Common failure patterns are identified
- Recommendations become more accurate
- Verification thresholds adapt to project needs
Create .claude-flow/pair.json
:
{
"mode": "strict",
"threshold": 0.95,
"autoRollback": true,
"checks": {
"compile": true,
"test": true,
"lint": true,
"security": true,
"performance": false
},
"agents": ["coder", "reviewer"],
"monitoring": {
"realtime": true,
"dashboard": true,
"notifications": true
},
"training": {
"enabled": true,
"learningRate": 0.1,
"autoFeed": true
}
Create ~/.claude-flow/preferences.json
:
{
"pair": {
"defaultMode": "strict",
"autoStart": false,
"verbosity": "normal",
"theme": "dark",
"notifications": {
"success": false,
"failure": true,
"rollback": true
}
}
}
- All changes are verified before acceptance
- Cryptographic signing of verified changes
- Audit trail of all modifications
- Rollback capability for security issues
- Local verification (no code sent to external servers)
- Optional telemetry (disabled by default)
- Encrypted storage of session data
- Configurable data retention
// No more automatic spam - manual control
class OptimizedSession {
constructor() {
this.autoVerify = false; // Off by default
this.verificationCooldown = 60000; // 60s minimum
this.isVerifying = false; // Prevent concurrent checks
}
async runVerification() {
// Check cooldown
if (Date.now() - this.lastCheck < this.cooldown) {
return; // Skip if too soon
}
// Prevent concurrent runs
if (this.isVerifying) return;
this.isVerifying = true;
// Run weighted checks...
this.isVerifying = false;
}
}
// Graduated scoring based on actual errors
function calculateScore(output) {
const errors = (output.match(/error/gi) || []).length;
const warnings = (output.match(/warning/gi) || []).length;
// Deduct 0.1 per error, 0.05 per warning
let score = 1.0;
score -= errors * 0.1;
score -= warnings * 0.05;
// Minimum scores to avoid 0
if (errors > 0) return Math.max(0.2, score);
if (warnings > 0) return Math.max(0.7, score);
return score;
}
Before Optimization:
- Verification every 30 seconds
- CPU usage: 10-17% constant
- 120 checks per hour
After Optimization:
- Manual verification only
- CPU usage: <1% idle
- On-demand checks only
- IDE Plugins: Native VSCode, IntelliJ, and Vim integrations
- Voice Control: Voice-activated pair programming
- AR/VR Support: Immersive pair programming environments
- Team Mode: Multiple developers with AI agents
- Learning Mode: AI learns your coding style over time
- Predictive verification based on code patterns
- Natural language programming interfaces
- Automated refactoring suggestions
- Cross-language pair programming support
# Built-in help
npx claude-flow@alpha pair --help
# Interactive tutorial
npx claude-flow@alpha pair --tutorial
# Community forum
https://github.com/ruvnet/claude-flow/discussions
We welcome contributions to improve the Pair Programming System:
- Fork the repository
- Create a feature branch
- Implement your enhancement
- Ensure verification passes
- Submit a pull request
The Pair Programming System transforms software development into a collaborative, verified, and continuously validated process. By combining human creativity with AI verification, we achieve unprecedented code quality and reliability.