Skip to content

Pair Programming System

rUv edited this page Aug 13, 2025 · 2 revisions

Pair Programming System

Overview

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.

Key Features

  • 🔍 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

System Architecture

┌─────────────────────────────────────────────────────────────┐
│                  Pair Programming System                      │
├─────────────────────────────────────────────────────────────┤
│                                                               │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │   Human      │  │     AI       │  │ Verification │      │
│  │  Developer   │←→│    Agent     │←→│   Engine     │      │
│  └──────────────┘  └──────────────┘  └──────────────┘      │
│         ↓                  ↓                  ↓              │
│  ┌────────────────────────────────────────────────────┐      │
│  │           Continuous Integration Pipeline           │      │
│  └────────────────────────────────────────────────────┘      │
│         ↓                  ↓                  ↓              │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │  File Watch  │  │   Testing    │  │   Rollback   │      │
│  │   System     │  │  Framework   │  │   Manager    │      │
│  └──────────────┘  └──────────────┘  └──────────────┘      │
│                                                               │
└─────────────────────────────────────────────────────────────┘

Getting Started

Quick Start with Verification

# 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

Basic Usage

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

Configuration Options

# 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

Verification Modes

1. Strict Mode (Recommended for Production)

npx claude-flow@alpha pair --mode strict
  • Truth threshold: 0.95
  • Auto-rollback: Enabled
  • All checks: Required
  • Real-time validation: Enabled

2. Standard Mode (Default)

npx claude-flow@alpha pair --mode standard
  • Truth threshold: 0.85
  • Auto-rollback: Optional
  • Core checks: Required
  • Real-time validation: Enabled

3. Development Mode

npx claude-flow@alpha pair --mode development
  • Truth threshold: 0.75
  • Auto-rollback: Disabled
  • Basic checks: Required
  • Real-time validation: Optional

Workflow Process

1. Session Initialization

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

2. Interactive 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

3. Optimized Verification Flow

// 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();
}

Optimized Verification System

Weighted Quality Checks

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;
}

Performance Checks

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
  }
};

AI Agent Capabilities

Code Review

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

Intelligent Suggestions

// 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

Integration with Development Tools

VSCode Integration

// .vscode/settings.json
{
  "claude-flow.pair": {
    "enabled": true,
    "autoStart": true,
    "threshold": 0.95,
    "mode": "strict"
  }
}

Git Hooks

# .git/hooks/pre-commit
#!/bin/bash
npx claude-flow@alpha pair --verify --threshold 0.95

CI/CD Pipeline

# .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

Monitoring and Metrics

Interactive Session Display

💻 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%

Session Commands

# Check current status
/status

# View quality metrics
/metrics

# Toggle auto-verification
/auto

# Run manual verification
/verify

# Run tests
/test

Advanced Features

1. Pattern Learning

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);

2. Multi-Agent Collaboration

# 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

3. Context Awareness

// System maintains context across files
const context = {
  project: analyzeProject(),
  dependencies: analyzeDependencies(),
  architecture: analyzeArchitecture(),
  history: analyzeGitHistory()
};

// Context-aware suggestions
suggestions = generateSuggestions(change, context);

Best Practices

1. Start Sessions Early

Begin pair programming at the start of your work:

# Morning routine
cd my-project
npx claude-flow@alpha pair --start --mode strict

2. Incremental Development

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
}

3. Review Verification Feedback

# Always check why verification failed
npx claude-flow@alpha truth --analyze

# Understand patterns
npx claude-flow@alpha pair --report

Troubleshooting

Common Issues

1. Verification Loop / Spam

# 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

2. Low Verification Scores

# 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

3. Session Not Responding

# 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

4. Performance Issues

# Use manual verification only
npx claude-flow@alpha pair --start --verify
# Don't use --auto flag

# Check metrics to identify patterns
/metrics  # During session

Training Integration (NEW!)

The Pair Programming system now integrates with the verification-training system for continuous improvement:

How It Works

  1. Every pair session generates verification data
  2. Verification results feed the training system
  3. System learns which patterns lead to success
  4. Future sessions benefit from improved predictions

Using Training with Pair Programming

# 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

Learning Benefits

  • Agent reliability improves with each session
  • Common failure patterns are identified
  • Recommendations become more accurate
  • Verification thresholds adapt to project needs

Configuration Files

Project Configuration

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
  }

Personal Preferences

Create ~/.claude-flow/preferences.json:

{
  "pair": {
    "defaultMode": "strict",
    "autoStart": false,
    "verbosity": "normal",
    "theme": "dark",
    "notifications": {
      "success": false,
      "failure": true,
      "rollback": true
    }
  }
}

Security Considerations

Code Protection

  • All changes are verified before acceptance
  • Cryptographic signing of verified changes
  • Audit trail of all modifications
  • Rollback capability for security issues

Privacy

  • Local verification (no code sent to external servers)
  • Optional telemetry (disabled by default)
  • Encrypted storage of session data
  • Configurable data retention

Performance Optimization (NEW!)

Verification Control

// 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;
  }
}

Intelligent Scoring

// 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;
}

Resource Usage

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

Future Roadmap

Planned Features

  1. IDE Plugins: Native VSCode, IntelliJ, and Vim integrations
  2. Voice Control: Voice-activated pair programming
  3. AR/VR Support: Immersive pair programming environments
  4. Team Mode: Multiple developers with AI agents
  5. Learning Mode: AI learns your coding style over time

Research Areas

  • Predictive verification based on code patterns
  • Natural language programming interfaces
  • Automated refactoring suggestions
  • Cross-language pair programming support

Community and Support

Getting Help

# 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

Contributing

We welcome contributions to improve the Pair Programming System:

  1. Fork the repository
  2. Create a feature branch
  3. Implement your enhancement
  4. Ensure verification passes
  5. Submit a pull request

Related Documentation


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.

Clone this wiki locally