Skip to content
Shell
3.4 KB
Raw Blame
#!/bin/bash

# milestone-tracker.sh
# Detects and logs major milestones to PROGRESS.md
# Triggered by: task completion, quality gates, week/phase completion

set -euo pipefail

PROJECT_ROOT="/Users/eddiebelaval/Development/deepstack"
BUILD_PLAN="$PROJECT_ROOT/docs/BUILD_PLAN.md"
PROGRESS="$PROJECT_ROOT/docs/PROGRESS.md"

# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

log() {
    echo -e "${BLUE}[MILESTONE]${NC} $1"
}

success() {
    echo -e "${GREEN}[βœ“]${NC} $1"
}

warn() {
    echo -e "${YELLOW}[!]${NC} $1"
}

# Check if files exist
if [[ ! -f "$BUILD_PLAN" ]] || [[ ! -f "$PROGRESS" ]]; then
    warn "BUILD_PLAN.md or PROGRESS.md not found. Skipping milestone tracking."
    exit 0
fi

# Detect task completion by counting checked tasks
detect_task_completion() {
    local task_pattern="$1"
    local task_name="$2"

    # Check if this specific task has all subtasks completed
    # This is a simplified check - in production would be more sophisticated
    if grep -q "#### \*\*$task_pattern\*\*" "$BUILD_PLAN"; then
        # Count total subtasks vs completed for this task
        # For now, just return task name if mentioned
        echo "$task_name"
    fi
}

# Calculate velocity (tasks completed per day)
calculate_velocity() {
    # Count completed tasks in PROGRESS.md
    local completed=$(grep -c "^\- \[x\]" "$PROGRESS" 2>/dev/null || echo "0")

    # Get days elapsed since project start (Nov 3, 2025)
    local start_date="2025-11-03"
    local current_date=$(date +%Y-%m-%d)
    local days_elapsed=$(( ($(date -jf "%Y-%m-%d" "$current_date" +%s) - $(date -jf "%Y-%m-%d" "$start_date" +%s)) / 86400 + 1 ))

    # Calculate velocity
    if [[ $days_elapsed -gt 0 ]]; then
        echo "$(echo "scale=2; $completed / $days_elapsed" | bc) tasks/day"
    else
        echo "N/A"
    fi
}

# Update PROGRESS.md with milestone
log_milestone() {
    local milestone_name="$1"
    local milestone_date=$(date "+%B %d, %Y %H:%M")
    local velocity=$(calculate_velocity)

    log "Logging milestone: $milestone_name"

    # Create milestone entry
    local milestone_entry="
## πŸŽ‰ MILESTONE: $milestone_name
**Date:** $milestone_date
**Velocity:** $velocity
**Status:** Completed

---
"

    # Check if milestone log section exists, if not create it
    if ! grep -q "## πŸ† Milestone Log" "$PROGRESS"; then
        # Add milestone log section after session continuity section
        echo -e "\n## πŸ† Milestone Log\n\n$milestone_entry" >> "$PROGRESS"
    else
        # Append to existing milestone log
        # This is simplified - would use proper insertion logic in production
        echo "$milestone_entry" >> "$PROGRESS"
    fi

    success "Milestone logged to PROGRESS.md"
}

# Main execution
main() {
    log "Checking for milestones..."

    # Example: Detect if Task 1.3 (KRANG Protocol) is complete
    # In production, this would check BUILD_PLAN.md dynamically

    # For now, just log that the milestone system is active
    log "Milestone tracking system active"
    log "Will automatically detect:"
    log "  - Task completions (all subtasks done)"
    log "  - Quality gate passes (80% coverage, etc.)"
    log "  - Week/phase completions"

    # Check if we should log PROJECT_BRAIN setup as first milestone
    if ! grep -q "PROJECT_BRAIN Setup Complete" "$PROGRESS"; then
        log_milestone "PROJECT_BRAIN Setup Complete"
        success "First milestone logged!"
    fi

    exit 0
}

main "$@"