feat: implement 7-phase morning start protocol and enhanced health checks

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
ja
2026-03-17 16:50:55 +01:00
co-authored by Junie
parent 4c489ded5c
commit d2067dfb91
2 changed files with 164 additions and 79 deletions
+131 -61
View File
@@ -2,83 +2,153 @@
set -euo pipefail set -euo pipefail
# saTway Daily Routine - 7-phase morning workflow # saTway Daily Routine - 7-phase morning workflow
# Implements "Morning Start Protocol (15 Min)"
mkdir -p "$HOME/logs" 2>/dev/null || true mkdir -p "$HOME/logs" 2>/dev/null || true
LOCAL_LOG="$HOME/logs/daily-routine-$(date +%Y%m%d).log" LOCAL_LOG="$HOME/logs/daily-routine-$(date +%Y%m%d).log"
HEALTH_SCRIPT="$(dirname "$0")/morning-health-check.sh" HEALTH_SCRIPT="$(dirname "$0")/morning-health-check.sh"
WORKSPACE="$HOME/internal/mw-pfeddersheim-workstation"
echo "--- Starting Daily Routine $(date) ---" | 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'
# Phase 0: Health check log() {
echo "[Phase 0/6] Running health check..." | tee -a "$LOCAL_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 if [ -x "$HEALTH_SCRIPT" ]; then
HEALTH_EXIT=0 HEALTH_EXIT=0
bash "$HEALTH_SCRIPT" 2>&1 | tee -a "$LOCAL_LOG" || HEALTH_EXIT=$? # 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 if [ "$HEALTH_EXIT" -eq 2 ]; then
echo " CRITICAL: Exiting daily routine" | tee -a "$LOCAL_LOG" log "\n${RED}CRITICAL: Health check failed with critical errors.${NC}"
exit 2 # 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 elif [ "$HEALTH_EXIT" -eq 1 ]; then
echo " WARNING: Proceeding with warnings" | tee -a "$LOCAL_LOG" log "\n${YELLOW}WARNING: Health check finished with warnings.${NC}"
fi fi
else else
echo " WARNING: health check script not found" | tee -a "$LOCAL_LOG" log "${YELLOW}WARNING: Health check script not found or not executable${NC}"
fi fi
}
# Phase 1: Log review phase_0_readiness() {
echo "[Phase 1/6] Reviewing error logs (last 24h)..." | tee -a "$LOCAL_LOG" phase_header "0" "Physical & Mental Readiness"
if command -v journalctl &> /dev/null; then log "Checklist:"
ERRORS=$(journalctl -p err --since "24 hours ago" --no-pager 2>/dev/null | tail -20 || true) log " [ ] Hydrated"
if [ -z "$ERRORS" ]; then log " [ ] Light movement"
echo " No errors found" | tee -a "$LOCAL_LOG" 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 else
echo "$ERRORS" | tee -a "$LOCAL_LOG" log " SKIP: Not on macOS"
fi 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 else
echo " journalctl not available" | tee -a "$LOCAL_LOG" log "${YELLOW}WARNING: cline CLI not found${NC}"
fi fi
}
# Phase 2: Security check phase_7_launch() {
echo "[Phase 2/6] Security status..." | tee -a "$LOCAL_LOG" phase_header "7" "Launch Deep Work"
if systemctl is-active --quiet fail2ban 2>/dev/null; then log "Ready to start?"
echo " fail2ban: active" | tee -a "$LOCAL_LOG" log " 1. Create branch: git checkout -b feat/\$(date +%Y%m%d)_morning_start"
else log " 2. Start timer: timer 90m \"Deep work complete!\" &"
echo " fail2ban: not running" | tee -a "$LOCAL_LOG" log " 3. FIRST ACTION: Write ONE thing that proves work has started (e.g., 1 failing test)."
fi }
echo " Recent sudo:" | tee -a "$LOCAL_LOG"
sudo last -5 2>/dev/null | tee -a "$LOCAL_LOG" || true
# Phase 3: Backup verification # Command line interface
echo "[Phase 3/6] Backup verification..." | tee -a "$LOCAL_LOG" case "${1:-morning}" in
if [ -d "/var/log/satway" ]; then "health")
RECENT=$(find /var/log/satway -type f -mtime -1 2>/dev/null | wc -l) run_health_check
echo " /var/log/satway: ${RECENT} file(s) modified in last 24h" | tee -a "$LOCAL_LOG" ;;
else "morning")
echo " /var/log/satway: not found" | tee -a "$LOCAL_LOG" log "--- Starting Lightweight Daily Routine $(date) ---"
fi phase_2_validation
log "\n--- Daily Routine Finished $(date) ---"
# Phase 4: Update check ;;
echo "[Phase 4/6] Checking for updates..." | tee -a "$LOCAL_LOG" "morning-full")
if command -v checkupdates &> /dev/null; then log "--- Starting Full Morning Protocol $(date) ---"
UPDATES=$(set +o pipefail; checkupdates 2>/dev/null | wc -l) phase_0_readiness
echo " ${UPDATES} package(s) pending" | tee -a "$LOCAL_LOG" phase_1_context
elif command -v pacman &> /dev/null; then phase_2_validation
echo " Run: pacman -Syu" | tee -a "$LOCAL_LOG" phase_3_priority
else phase_4_sync
echo " No package manager detected" | tee -a "$LOCAL_LOG" phase_5_warmup
fi phase_6_ai_setup
phase_7_launch
# Phase 5: Workspace setup log "\n--- Full Morning Protocol Finished $(date) ---"
echo "[Phase 5/6] Workspace sync..." | tee -a "$LOCAL_LOG" ;;
WORKSPACE="$HOME/internal/mw-pfeddersheim-workstation" *)
if [ -d "$WORKSPACE/.git" ]; then echo "Usage: $0 {health|morning|morning-full}"
git -C "$WORKSPACE" fetch --all 2>&1 | tee -a "$LOCAL_LOG" || true exit 1
echo " Fetch complete" | tee -a "$LOCAL_LOG" ;;
else esac
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"
echo "--- Daily Routine Finished $(date) ---" | tee -a "$LOCAL_LOG"
+19 -4
View File
@@ -48,14 +48,29 @@ else
echo " Workspace not found at $WORKSPACE" | tee -a "$LOCAL_LOG" echo " Workspace not found at $WORKSPACE" | tee -a "$LOCAL_LOG"
fi fi
# Phase 2: Docker & Uptime # Phase 2: Docker, Uptime & Dependencies
echo "[Phase 2] Checking services..." | tee -a "$LOCAL_LOG" echo "[Phase 2] Checking services & dependencies..." | tee -a "$LOCAL_LOG"
if command -v docker &> /dev/null; then if command -v docker &> /dev/null; then
if docker info &> /dev/null; then
RUNNING=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l) RUNNING=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l)
echo " Docker: ${RUNNING} container(s) running" | tee -a "$LOCAL_LOG" echo -e " ${GREEN}Docker: ${RUNNING} container(s) running${NC}" | tee -a "$LOCAL_LOG"
else else
echo " Docker: not installed" | tee -a "$LOCAL_LOG" echo -e " ${YELLOW}Docker: installed but not running${NC}" | tee -a "$LOCAL_LOG"
[ "$WORST_STATE" -lt 1 ] && WORST_STATE=1
fi fi
else
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 " Uptime: $(uptime -p)" | tee -a "$LOCAL_LOG"
echo "--- Health Check Finished $(date) ---" | tee -a "$LOCAL_LOG" echo "--- Health Check Finished $(date) ---" | tee -a "$LOCAL_LOG"