Back to Ruflo

Pair Programming Command Optimization

v2/docs/development/pair-optimization.md

3.6.304.4 KB
Original Source

Pair Programming Command Optimization

Problem Solved

The pair programming command was running verification checks continuously every 30 seconds, causing:

  • Excessive CPU usage
  • Constant terminal output spam
  • Poor user experience with repeated failure messages
  • Inability to use the interactive session properly

Optimizations Implemented

1. Removed Automatic Interval-Based Verification

  • Before: setInterval ran verification every 30 seconds automatically
  • After: Verification only runs on-demand or with explicit auto-verify flag

2. Added Verification Cooldown

  • 60-second cooldown between automatic verifications
  • Prevents verification spam even with auto-verify enabled
  • Manual /verify command bypasses cooldown

3. Intelligent Scoring System

javascript
// Old: Binary pass/fail (0.5 or 1.0)
const score = passed ? 1.0 : 0.5;

// New: Graduated scoring based on error count
if (output.includes('error')) {
  const errorCount = (output.match(/error/gi) || []).length;
  score = Math.max(0.2, 1.0 - (errorCount * 0.1));
} else if (output.includes('warning')) {
  const warningCount = (output.match(/warning/gi) || []).length;
  score = Math.max(0.7, 1.0 - (warningCount * 0.05));
}

4. Weighted Verification Checks

  • Type Check: 40% weight (most important)
  • Linting: 30% weight
  • Build: 30% weight

5. Concurrent Verification Prevention

  • Added isVerifying flag to prevent multiple simultaneous checks
  • Returns early if verification already in progress

6. Manual Control Options

  • /verify - Run verification manually
  • /auto - Toggle automatic verification on/off
  • /metrics - View verification history
  • /status - Check current settings

7. Better Error Messages

  • Only shows detailed suggestions for very low scores (<0.5)
  • Cleaner output with icons (✅, ⚠️, ❌)
  • Timestamps for verification history

Usage Patterns

bash
# Start with manual verification only
./claude-flow pair --start --verify

# Run verification when needed
/verify

Auto Verification (For Monitoring)

bash
# Enable auto-verify with 60s cooldown
./claude-flow pair --start --verify --auto

# Toggle during session
/auto

Testing Integration

bash
# Enable testing without auto-run
./claude-flow pair --start --test

# Run tests manually
/test

Performance Impact

Before Optimization

  • Verification every 30 seconds
  • ~3-5 seconds per verification
  • 10-17% CPU usage from verification alone
  • 120 verifications per hour

After Optimization

  • Verification on-demand only
  • 60-second cooldown if auto-enabled
  • <1% CPU usage when idle
  • ~60 verifications per hour maximum

Command Reference

CommandDescriptionAuto-Verify Impact
/verifyRun verification nowBypasses cooldown
/testRun tests nowIndependent
/autoToggle auto-verifyEnables/disables
/statusShow settingsNo impact
/metricsShow historyNo impact
/commitPre-commit checkRuns verification

Configuration Flags

FlagDefaultDescription
--verifyfalseEnable verification system
--autofalseEnable automatic verification
--testfalseEnable test system
--threshold0.95Verification pass threshold

Best Practices

  1. Start with manual verification - Use --verify without --auto
  2. Run verification before commits - Use /commit command
  3. Check metrics periodically - Use /metrics to track trends
  4. Enable auto-verify sparingly - Only for long sessions needing monitoring
  5. Use weighted scores - Trust the intelligent scoring system

Session Data Structure

json
{
  "id": "pair_1755038032183",
  "mode": "switch",
  "verify": true,
  "autoVerify": false,
  "verificationScores": [
    {
      "score": 0.82,
      "timestamp": 1755038045000,
      "results": [
        { "name": "Type Check", "score": 0.8 },
        { "name": "Linting", "score": 0.85 },
        { "name": "Build", "score": 0.82 }
      ]
    }
  ]
}

Future Enhancements

  • File watcher integration for smart verification
  • Incremental verification (only changed files)
  • Caching of verification results
  • Parallel verification checks
  • Custom verification commands
  • Integration with git hooks