# Task: Monitor Progress

> ✅ **Works with any IDE** - This task provides bash scripts for progress monitoring

## Description

Continuously monitors progress across all parallel development worktrees, providing real-time status updates and identifying potential issues.

## Steps

1. **Set Up Monitoring Infrastructure**

   ```bash
   COORD_DIR="/tmp/$(basename $(pwd))-ck-parallel"

   # Create monitoring script
   cat > "$COORD_DIR/monitor.sh" << 'EOF'
   #!/bin/bash

   while true; do
     clear
     echo "=== Parallel Development Monitor ==="
     echo "Time: $(date '+%Y-%m-%d %H:%M:%S')"
     echo ""

     # Check each worktree
     for wt in $(git worktree list --porcelain | grep "worktree" | cut -d' ' -f2); do
       if [[ "$wt" != *"ck-website"* ]] || [[ "$wt" == "$(pwd)" ]]; then
         continue
       fi

       echo "📁 $(basename $wt):"
       cd "$wt" 2>/dev/null

       # Git status
       CHANGES=$(git status --porcelain | wc -l)
       BRANCH=$(git branch --show-current)
       COMMITS_AHEAD=$(git rev-list --count origin/main..$BRANCH 2>/dev/null || echo "0")

       echo "  Branch: $BRANCH"
       echo "  Changes: $CHANGES files modified"
       echo "  Commits: $COMMITS_AHEAD ahead of main"

       # Check for test results
       if [[ -f "test-results.log" ]]; then
         echo "  Tests: $(tail -1 test-results.log)"
       fi

       echo ""
     done

     # Show recent updates
     echo "=== Recent Updates ==="
     tail -5 "$COORD_DIR/agent-updates.log" 2>/dev/null || echo "No updates yet"

     echo ""
     echo "=== Alerts ==="
     tail -3 "$COORD_DIR/coordinator-alerts.log" 2>/dev/null || echo "No alerts"

     sleep 30
   done
   EOF
   chmod +x "$COORD_DIR/monitor.sh"
   ```

2. **Create Progress Dashboard**

   ```bash
   cat > "$COORD_DIR/update-dashboard.sh" << 'EOF'
   #!/bin/bash

   DASHBOARD="$COORD_DIR/dashboard.md"

   cat > "$DASHBOARD" << 'HEADER'
   # Parallel Development Dashboard
   HEADER

   echo "Last Updated: $(date '+%Y-%m-%d %H:%M:%S')" >> "$DASHBOARD"
   echo "" >> "$DASHBOARD"

   # Phase status
   echo "## Active Development" >> "$DASHBOARD"
   echo "| Worktree | Branch | Files | Commits | Status |" >> "$DASHBOARD"
   echo "|----------|--------|-------|---------|--------|" >> "$DASHBOARD"

   for wt in $(git worktree list --porcelain | grep "worktree" | cut -d' ' -f2); do
     if [[ "$wt" == "$(pwd)" ]]; then continue; fi

     cd "$wt" 2>/dev/null || continue
     BRANCH=$(git branch --show-current)
     CHANGES=$(git status --porcelain | wc -l)
     COMMITS=$(git rev-list --count origin/main..$BRANCH 2>/dev/null || echo "0")
     STATUS="Active"

     echo "| $(basename $wt) | $BRANCH | $CHANGES | $COMMITS | $STATUS |" >> "$DASHBOARD"
   done

   echo "" >> "$DASHBOARD"

   # Story completion
   echo "## Story Progress" >> "$DASHBOARD"
   # Parse from agent updates log

   EOF
   chmod +x "$COORD_DIR/update-dashboard.sh"
   ```

3. **Monitor Git Activity**

   ```bash
   cat > "$COORD_DIR/git-activity.sh" << 'EOF'
   #!/bin/bash

   echo "=== Git Activity Monitor ==="

   for wt in $(git worktree list --porcelain | grep "worktree" | cut -d' ' -f2); do
     if [[ "$wt" == "$(pwd)" ]]; then continue; fi

     echo -e "\n📁 $(basename $wt):"
     cd "$wt" 2>/dev/null || continue

     # Recent commits
     echo "Recent commits:"
     git log --oneline -5 --no-decorate

     # Current changes
     echo -e "\nCurrent changes:"
     git diff --stat
   done
   EOF
   chmod +x "$COORD_DIR/git-activity.sh"
   ```

4. **Check for Conflicts**

   ```bash
   cat > "$COORD_DIR/conflict-check.sh" << 'EOF'
   #!/bin/bash

   echo "=== Conflict Detection ==="

   CONFLICTS=0

   for wt in $(git worktree list --porcelain | grep "worktree" | cut -d' ' -f2); do
     if [[ "$wt" == "$(pwd)" ]]; then continue; fi

     cd "$wt" 2>/dev/null || continue
     BRANCH=$(git branch --show-current)

     # Test merge
     git merge --no-commit --no-ff origin/main > /dev/null 2>&1
     if [[ $? -ne 0 ]]; then
       echo "⚠️  Potential conflicts in $(basename $wt) ($BRANCH)"
       CONFLICTS=$((CONFLICTS + 1))
     fi
     git merge --abort 2>/dev/null
   done

   if [[ $CONFLICTS -eq 0 ]]; then
     echo "✅ No merge conflicts detected"
   else
     echo "❌ Found $CONFLICTS potential conflicts"
   fi
   EOF
   chmod +x "$COORD_DIR/conflict-check.sh"
   ```

5. **Create Alert System**

   ```bash
   cat > "$COORD_DIR/check-alerts.sh" << 'EOF'
   #!/bin/bash

   # Check for blocked stories
   grep -i "blocked" "$COORD_DIR/agent-updates.log" 2>/dev/null | tail -5

   # Check for failing tests
   for wt in $(git worktree list --porcelain | grep "worktree" | cut -d' ' -f2); do
     if [[ -f "$wt/test-results.log" ]]; then
       grep -i "fail" "$wt/test-results.log" | tail -3
     fi
   done

   # Check for merge conflicts
   "$COORD_DIR/conflict-check.sh" | grep -E "⚠️|❌"
   EOF
   chmod +x "$COORD_DIR/check-alerts.sh"
   ```

## Monitoring Commands

### Real-time Monitor

```bash
$COORD_DIR/monitor.sh
```

### Update Dashboard

```bash
$COORD_DIR/update-dashboard.sh
cat $COORD_DIR/dashboard.md
```

### Check Git Activity

```bash
$COORD_DIR/git-activity.sh
```

### Detect Conflicts

```bash
$COORD_DIR/conflict-check.sh
```

### Review Alerts

```bash
$COORD_DIR/check-alerts.sh
```

## Metrics to Track

- Files changed per story
- Commits per story
- Time per story phase
- Test pass/fail rates
- Merge conflict frequency
- Blocker resolution time

## Alert Conditions

- Story blocked for > 30 minutes
- Test failures in any worktree
- Merge conflicts detected
- No activity for > 1 hour
- Worktree in dirty state

## Reporting

Generate periodic reports:

```bash
# Hourly summary
echo "=== Hourly Report $(date) ===" >> $COORD_DIR/reports.log
$COORD_DIR/update-dashboard.sh
cat $COORD_DIR/dashboard.md >> $COORD_DIR/reports.log
```
