AUTOMATION SETUP GUIDE

Documentation for Developers

🤖 Automation Setup Guide

Preventing Performance Issues Automatically

Date: October 20, 2025
Status: ✅ PRODUCTION READY
Purpose: Set up automated prevention of monorepo performance issues


🎯 Overview

This guide helps you set up automatic prevention of performance issues in the monorepo. Once configured, the system will:


🚀 Quick Setup (5 Minutes)

One Command Setup:

yarn setup:automation

This will:

  1. Install git hooks (Husky)
  2. Set up monitoring daemon (macOS)
  3. Configure automatic health checks

Verify Setup:

# Check if git hooks are installed
ls -la .husky/pre-commit

# Check if monitoring daemon is running
launchctl list | grep monorepo

# Test health check
yarn crash:check

📋 Manual Setup (Step by Step)

Step 1: Install Git Hooks

# Install Husky (if not already installed)
npm install --save-dev husky
npx husky install

# The pre-commit hook is already created at:
# .husky/pre-commit

What it does:

Test it:

git add .
git commit -m "test"
# You should see health check running

Step 2: Set Up Monitoring Daemon (macOS)

# Run the setup script
yarn setup:monitoring

# Or manually:
bash tools/scripts/setup-monitoring-daemon.sh

What it does:

Verify it's running:

# Check if daemon is loaded
launchctl list | grep monorepo

# View logs
tail -f ~/Library/Logs/monorepo-health.log

Management commands:

# Start daemon
launchctl load ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

# Stop daemon
launchctl unload ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

# Restart daemon
launchctl unload ~/Library/LaunchAgents/com.monorepo.healthcheck.plist
launchctl load ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

Step 3: Configure Cursor/VS Code

The setup has already created:

Automatic tasks include:

  1. Health check on folder open
  2. Continuous monitoring option
  3. Performance monitoring during builds

Manual trigger:


Step 4: Set Up CI/CD (GitHub Actions)

The workflow file is already created at: .github/workflows/performance-check.yml

It will:

No action needed - it will run automatically on your next PR.


🔧 Configuration

Monitoring Frequency

Edit the daemon to change frequency:

# Edit the plist file
nano ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

# Change this value (in seconds):
<key>StartInterval</key>
<integer>1800</integer>  <!-- 30 minutes = 1800 seconds -->

# Reload daemon after changes
launchctl unload ~/Library/LaunchAgents/com.monorepo.healthcheck.plist
launchctl load ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

Recommended frequencies:


Health Check Thresholds

Edit tools/scripts/monorepo-health-check.js:

// Current thresholds:
const health = {
  maxNodeProcesses: 10,        // Increase if needed
  maxCursorProcesses: 5,       // Increase if needed
  maxTsserverProcesses: 4,     // Increase if needed
  maxMemoryMB: 8 * 1024        // 8GB, increase for more memory
};

Git Hook Behavior

Edit .husky/pre-commit to change behavior:

# Current behavior: Fails commit if unhealthy
# Change to: Warn but allow commit
if [ $? -ne 0 ]; then
  echo "⚠️  Warning: System health check failed"
  echo "    Proceeding with commit anyway..."
  # Remove 'exit 1' to allow commit
fi

📊 Monitoring & Logs

View Monitoring Logs:

# Real-time monitoring
tail -f ~/Library/Logs/monorepo-health.log

# Error logs
tail -f ~/Library/Logs/monorepo-health-error.log

# Last 50 entries
tail -50 ~/Library/Logs/monorepo-health.log

Health Check History:

# View historical health scores
grep "HEALTH SCORE" ~/Library/Logs/monorepo-health.log

# View critical issues
grep "CRITICAL" ~/Library/Logs/monorepo-health.log

# View automatic fixes
grep "Cleanup" ~/Library/Logs/monorepo-health.log

🎯 Daily Workflow

With Automation Enabled:

Morning:
  1. Open Cursor
     → Automatic health check runs ✅
  
  2. Start working
     → Monitoring daemon checks every 30 min ✅
  
  3. Commit changes
     → Pre-commit hook checks health ✅
  
  4. Push to GitHub
     → CI/CD checks performance ✅

If issues detected:
  → Automatic cleanup runs ✅
  → Desktop notification (optional) 📱
  → Logs to file for review 📝

Manual Checks (Optional):

# Quick health check anytime
yarn crash:check

# Full performance report
yarn perf:report

# Force cleanup if needed
yarn crash:fix

🚨 Troubleshooting Automation

Git Hooks Not Running?

# Reinstall hooks
npx husky install

# Verify hook is executable
chmod +x .husky/pre-commit

# Test hook manually
.husky/pre-commit

Monitoring Daemon Not Working?

# Check if it's loaded
launchctl list | grep monorepo

# Check logs for errors
tail -20 ~/Library/Logs/monorepo-health-error.log

# Reload daemon
bash tools/scripts/setup-monitoring-daemon.sh

Cursor Tasks Not Running?

# Verify tasks file exists
cat .vscode/tasks.json

# Manually run task:
# Cmd+Shift+P → "Tasks: Run Task" → Select task

CI/CD Failing?

# Check workflow file
cat .github/workflows/performance-check.yml

# Test locally
yarn build:gograb:fast
node tools/scripts/performance-audit.js

🎉 Verification Checklist

After setup, verify everything is working:


📈 Expected Results

Before Automation:

After Automation:


🔄 Disabling Automation

Temporarily Disable:

# Disable git hooks
mv .husky/pre-commit .husky/pre-commit.disabled

# Disable monitoring daemon
launchctl unload ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

# Disable Cursor tasks
mv .vscode/tasks.json .vscode/tasks.json.disabled

Permanently Remove:

# Remove git hooks
rm -rf .husky

# Remove monitoring daemon
launchctl unload ~/Library/LaunchAgents/com.monorepo.healthcheck.plist
rm ~/Library/LaunchAgents/com.monorepo.healthcheck.plist

# Remove Cursor config
rm .vscode/tasks.json .vscode/settings.json

💡 Pro Tips

1. Custom Notifications (macOS)

Add to monorepo-health-check.js:

# Install node-notifier
yarn add -D node-notifier

# Add to script:
const notifier = require('node-notifier');
if (healthScore < 60) {
  notifier.notify({
    title: '⚠️ Monorepo Health Alert',
    message: `Health score: ${healthScore}%`,
    sound: true
  });
}

2. Slack Notifications

Add webhook to monitoring:

const axios = require('axios');
if (healthScore < 60) {
  axios.post(process.env.SLACK_WEBHOOK, {
    text: `Monorepo health critical: ${healthScore}%`
  });
}

3. Weekly Reports

Schedule weekly email reports:

# Add to crontab
0 9 * * MON cd /path/to/editor && yarn perf:report | mail -s "Weekly Performance Report" [email protected]

📚 Related Documentation


✅ Success Criteria

You'll know automation is working when:

  1. ✅ Health checks run without manual intervention
  2. ✅ You receive alerts before issues become critical
  3. ✅ Git commits are blocked when system is unhealthy
  4. ✅ Performance regressions are caught in CI/CD
  5. ✅ You never experience resource exhaustion again

Your monorepo is now self-monitoring and self-healing! 🚀


Last Updated: October 20, 2025
Setup Time: 5 minutes
Maintenance: Zero (fully automated)