# GPU Dev Server Extensions (managed by system - do not edit)
# This file is overwritten on every pod startup to ensure latest features.
# Put your personal customizations in ~/.zshrc instead.

# User identification (set by Lambda on startup)
export GPU_DEV_USER_ID="dev"

# Function to check for GPU reservation expiry warnings and startup script status
check_warnings() {
    # Check for startup script still running
    if [[ -f /home/dev/STARTUP_SCRIPT_RUNNING.txt ]]; then
        echo -e "\033[1;33m$(cat /home/dev/STARTUP_SCRIPT_RUNNING.txt)\033[0m"
    fi
    # Check for expiry warnings
    setopt NULL_GLOB 2>/dev/null
    local warning_files=(/home/dev/WARN_EXPIRES_IN_*MIN.txt)
    if [[ ${#warning_files[@]} -gt 0 ]] && [[ -f "${warning_files[1]}" ]]; then
        # Extract minutes from filename (e.g., WARN_EXPIRES_IN_15MIN.txt -> 15)
        local minutes="${warning_files[1]:t:r}"  # Get basename without extension
        minutes="${minutes#WARN_EXPIRES_IN_}"    # Remove prefix
        minutes="${minutes%MIN}"                 # Remove suffix
        echo -e "\033[1;31m🚨 URGENT: Server expires in <${minutes} minutes! 🚨\033[0m"
    fi
}

# Run warning check before every command prompt (zsh hook)
precmd() { check_warnings }

# Auto-cleanup of deprecated ANTHROPIC_MODEL pinning. An older docker image
# hardcoded ANTHROPIC_MODEL=us.anthropic.claude-sonnet-4-20250514-v1:0 in
# .shell_env, which then got cached on persistent disks. We unset it in the
# current session and strip the line from disk so it doesn't come back.
# Self-healing — once cleaned, the case statement no longer matches.
case "${ANTHROPIC_MODEL:-}" in
    *sonnet-4-20250514*)
        unset ANTHROPIC_MODEL
        if [ -f "$HOME/.shell_env" ]; then
            sed -i '/ANTHROPIC_MODEL.*sonnet-4-20250514/d' "$HOME/.shell_env" 2>/dev/null || true
        fi
        ;;
esac
