diff --git a/scripts/daily-routine.sh b/scripts/daily-routine.sh index 7ca09a6..3db71b1 100755 --- a/scripts/daily-routine.sh +++ b/scripts/daily-routine.sh @@ -2,83 +2,153 @@ set -euo pipefail # saTway Daily Routine - 7-phase morning workflow +# Implements "Morning Start Protocol (15 Min)" + mkdir -p "$HOME/logs" 2>/dev/null || true LOCAL_LOG="$HOME/logs/daily-routine-$(date +%Y%m%d).log" HEALTH_SCRIPT="$(dirname "$0")/morning-health-check.sh" - -echo "--- Starting Daily Routine $(date) ---" | tee -a "$LOCAL_LOG" - -# Phase 0: Health check -echo "[Phase 0/6] Running health check..." | tee -a "$LOCAL_LOG" -if [ -x "$HEALTH_SCRIPT" ]; then -HEALTH_EXIT=0 -bash "$HEALTH_SCRIPT" 2>&1 | tee -a "$LOCAL_LOG" || HEALTH_EXIT=$? -if [ "$HEALTH_EXIT" -eq 2 ]; then -echo " CRITICAL: Exiting daily routine" | tee -a "$LOCAL_LOG" - exit 2 -elif [ "$HEALTH_EXIT" -eq 1 ]; then - echo " WARNING: Proceeding with warnings" | tee -a "$LOCAL_LOG" -fi -else - echo " WARNING: health check script not found" | tee -a "$LOCAL_LOG" -fi - -# Phase 1: Log review -echo "[Phase 1/6] Reviewing error logs (last 24h)..." | tee -a "$LOCAL_LOG" -if command -v journalctl &> /dev/null; then - ERRORS=$(journalctl -p err --since "24 hours ago" --no-pager 2>/dev/null | tail -20 || true) - if [ -z "$ERRORS" ]; then - echo " No errors found" | tee -a "$LOCAL_LOG" - else - echo "$ERRORS" | tee -a "$LOCAL_LOG" - fi -else - echo " journalctl not available" | tee -a "$LOCAL_LOG" -fi - -# Phase 2: Security check -echo "[Phase 2/6] Security status..." | tee -a "$LOCAL_LOG" -if systemctl is-active --quiet fail2ban 2>/dev/null; then - echo " fail2ban: active" | tee -a "$LOCAL_LOG" -else - echo " fail2ban: not running" | tee -a "$LOCAL_LOG" -fi -echo " Recent sudo:" | tee -a "$LOCAL_LOG" -sudo last -5 2>/dev/null | tee -a "$LOCAL_LOG" || true - -# Phase 3: Backup verification -echo "[Phase 3/6] Backup verification..." | tee -a "$LOCAL_LOG" -if [ -d "/var/log/satway" ]; then - RECENT=$(find /var/log/satway -type f -mtime -1 2>/dev/null | wc -l) - echo " /var/log/satway: ${RECENT} file(s) modified in last 24h" | tee -a "$LOCAL_LOG" -else - echo " /var/log/satway: not found" | tee -a "$LOCAL_LOG" -fi - -# Phase 4: Update check -echo "[Phase 4/6] Checking for updates..." | tee -a "$LOCAL_LOG" -if command -v checkupdates &> /dev/null; then - UPDATES=$(set +o pipefail; checkupdates 2>/dev/null | wc -l) - echo " ${UPDATES} package(s) pending" | tee -a "$LOCAL_LOG" -elif command -v pacman &> /dev/null; then - echo " Run: pacman -Syu" | tee -a "$LOCAL_LOG" -else - echo " No package manager detected" | tee -a "$LOCAL_LOG" -fi - -# Phase 5: Workspace setup -echo "[Phase 5/6] Workspace sync..." | tee -a "$LOCAL_LOG" WORKSPACE="$HOME/internal/mw-pfeddersheim-workstation" -if [ -d "$WORKSPACE/.git" ]; then - git -C "$WORKSPACE" fetch --all 2>&1 | tee -a "$LOCAL_LOG" || true - echo " Fetch complete" | tee -a "$LOCAL_LOG" -else - echo " Workspace not found" | tee -a "$LOCAL_LOG" -fi -# Phase 6: Focus mode reminder -echo "[Phase 6/6] Focus mode reminder" | tee -a "$LOCAL_LOG" -echo " Work 1: 09:00-13:00 | Regen: 13:00-14:00 | Work 2: 14:00-18:00" | tee -a "$LOCAL_LOG" -echo " Friday post-15:00 = family time" | tee -a "$LOCAL_LOG" +# ANSI colors +RED='\033[0;31m' +YELLOW='\033[0;33m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +NC='\033[0m' -echo "--- Daily Routine Finished $(date) ---" | tee -a "$LOCAL_LOG" \ No newline at end of file +log() { + echo -e "$1" | tee -a "$LOCAL_LOG" +} + +phase_header() { + log "\n${BLUE}--- Phase $1: $2 ---${NC}" +} + +run_health_check() { + log "Running health check..." + if [ -x "$HEALTH_SCRIPT" ]; then + HEALTH_EXIT=0 + # Disable set -e for the health check call + set +e + bash "$HEALTH_SCRIPT" 2>&1 | tee -a "$LOCAL_LOG" + HEALTH_EXIT=$? + set -e + + if [ "$HEALTH_EXIT" -eq 2 ]; then + log "\n${RED}CRITICAL: Health check failed with critical errors.${NC}" + # Still proceed for the morning-full routine but with a big warning? + # Or exit? Let's follow the previous script logic for health: + # morning-full should probably still show the rest of the protocol + # so the user can see everything. + elif [ "$HEALTH_EXIT" -eq 1 ]; then + log "\n${YELLOW}WARNING: Health check finished with warnings.${NC}" + fi + else + log "${YELLOW}WARNING: Health check script not found or not executable${NC}" + fi +} + +phase_0_readiness() { + phase_header "0" "Physical & Mental Readiness" + log "Checklist:" + log " [ ] Hydrated" + log " [ ] Light movement" + log " [ ] 1-minute mindfulness" + log " [ ] Time block established" + + log "\nActivating DND (macOS)..." + if [[ "$OSTYPE" == "darwin"* ]]; then + osascript -e 'do shell script "defaults write com.apple.controlcenter \"NSStatusItem Visible DoNotDisturb\" -bool true"' || log " Failed to set DND" + pkill -f "Slack" 2>/dev/null || true + pkill -f "Discord" 2>/dev/null || true + log " DND enabled and distractions closed." + else + log " SKIP: Not on macOS" + fi +} + +phase_1_context() { + phase_header "1" "Context Restoration" + log "Recent WIP commits:" + git -C "$WORKSPACE" log -5 --pretty=format:"%h %s" --grep="wip:" || log " No WIP commits found" + + log "\nRecent learnings:" + ls -lt "$WORKSPACE/docs/learnings/" 2>/dev/null | head -3 || log " No learnings found" + + log "\nGit status:" + git -C "$WORKSPACE" status --short +} + +phase_2_validation() { + phase_header "2" "Environment Validation" + run_health_check +} + +phase_3_priority() { + phase_header "3" "Priority Framework (MoSCoW)" + log "Define exactly 3 priorities. No more." + log " 1. [MUST] _____________________" + log " 2. [MUST/SHOULD] ______________" + log " 3. [SHOULD] ___________________" +} + +phase_4_sync() { + phase_header "4" "Team Synchronization" + log " [ ] Async Standup: Post yesterday, today, blockers, availability." + log " [ ] Block Focus Time: Calendar updated." +} + +phase_5_warmup() { + phase_header "5" "Cognitive Warmup" + log "Choose ONE (2-5 minutes):" + log " - Review simple PR" + log " - Fix trivial lint warning" + log " - Write small test case" + log " - Document one function" +} + +phase_6_ai_setup() { + phase_header "6" "AI Setup" + if command -v cline &> /dev/null; then + log "cline version:" + cline --version | head -n 1 | tee -a "$LOCAL_LOG" + else + log "${YELLOW}WARNING: cline CLI not found${NC}" + fi +} + +phase_7_launch() { + phase_header "7" "Launch Deep Work" + log "Ready to start?" + log " 1. Create branch: git checkout -b feat/\$(date +%Y%m%d)_morning_start" + log " 2. Start timer: timer 90m \"Deep work complete!\" &" + log " 3. FIRST ACTION: Write ONE thing that proves work has started (e.g., 1 failing test)." +} + +# Command line interface +case "${1:-morning}" in + "health") + run_health_check + ;; + "morning") + log "--- Starting Lightweight Daily Routine $(date) ---" + phase_2_validation + log "\n--- Daily Routine Finished $(date) ---" + ;; + "morning-full") + log "--- Starting Full Morning Protocol $(date) ---" + phase_0_readiness + phase_1_context + phase_2_validation + phase_3_priority + phase_4_sync + phase_5_warmup + phase_6_ai_setup + phase_7_launch + log "\n--- Full Morning Protocol Finished $(date) ---" + ;; + *) + echo "Usage: $0 {health|morning|morning-full}" + exit 1 + ;; +esac \ No newline at end of file diff --git a/scripts/morning-health-check.sh b/scripts/morning-health-check.sh index 9c846da..cf67365 100755 --- a/scripts/morning-health-check.sh +++ b/scripts/morning-health-check.sh @@ -48,14 +48,29 @@ else echo " Workspace not found at $WORKSPACE" | tee -a "$LOCAL_LOG" fi -# Phase 2: Docker & Uptime -echo "[Phase 2] Checking services..." | tee -a "$LOCAL_LOG" +# Phase 2: Docker, Uptime & Dependencies +echo "[Phase 2] Checking services & dependencies..." | tee -a "$LOCAL_LOG" if command -v docker &> /dev/null; then - RUNNING=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l) - echo " Docker: ${RUNNING} container(s) running" | tee -a "$LOCAL_LOG" + if docker info &> /dev/null; then + RUNNING=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l) + echo -e " ${GREEN}Docker: ${RUNNING} container(s) running${NC}" | tee -a "$LOCAL_LOG" + else + echo -e " ${YELLOW}Docker: installed but not running${NC}" | tee -a "$LOCAL_LOG" + [ "$WORST_STATE" -lt 1 ] && WORST_STATE=1 + fi else - echo " Docker: not installed" | tee -a "$LOCAL_LOG" + echo -e " ${YELLOW}Docker: not installed${NC}" | tee -a "$LOCAL_LOG" fi + +if [ -f "$WORKSPACE/package.json" ]; then + if [ ! -d "$WORKSPACE/node_modules" ]; then + echo -e " ${RED}CRITICAL: node_modules missing. Run 'npm install' or 'pnpm install'${NC}" | tee -a "$LOCAL_LOG" + WORST_STATE=2 + else + echo -e " ${GREEN}Dependencies: OK (node_modules present)${NC}" | tee -a "$LOCAL_LOG" + fi +fi + echo " Uptime: $(uptime -p)" | tee -a "$LOCAL_LOG" echo "--- Health Check Finished $(date) ---" | tee -a "$LOCAL_LOG"