#!/bin/bash
# Load session state at the start of a session

STATE_FILE=".claude/state/session.json"

if [ -f "$STATE_FILE" ]; then
    # Check if state is recent (within last 24 hours)
    if [ "$(uname)" = "Darwin" ]; then
        # macOS
        FILE_AGE=$(( $(date +%s) - $(stat -f %m "$STATE_FILE") ))
    else
        # Linux
        FILE_AGE=$(( $(date +%s) - $(stat -c %Y "$STATE_FILE") ))
    fi

    # 24 hours = 86400 seconds
    if [ $FILE_AGE -lt 86400 ]; then
        echo "✓ Previous session state found ($(( FILE_AGE / 60 )) minutes ago)"

        # Check if there's an incomplete task
        if command -v jq &> /dev/null; then
            CURRENT_TASK=$(jq -r '.currentTask // empty' "$STATE_FILE" 2>/dev/null)
            if [ -n "$CURRENT_TASK" ]; then
                echo "ℹ️  Resuming: $CURRENT_TASK"
            fi
        fi
    else
        echo "ℹ️  Session state expired (>24h old)"
    fi
else
    echo "ℹ️  No previous session state"
fi

exit 0
