#!/bin/bash
# Hook: SessionStart (startup)
# Shows a random tip on every session start to encourage good practices.
#
# Tips are loaded from daily-tips.txt (one tip per line).

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TIPS_FILE="$SCRIPT_DIR/daily-tips.txt"

# Load tips
if [ ! -f "$TIPS_FILE" ]; then
  exit 0
fi

filtered=()
while IFS= read -r line || [ -n "$line" ]; do
  [ -n "$line" ] && filtered+=("$line")
done < "$TIPS_FILE"
total=${#filtered[@]}

if [ "$total" -eq 0 ]; then
  exit 0
fi

# Pick a random tip each session
tip_index=$(( RANDOM % total ))
tip="${filtered[$tip_index]}"

# Emit as systemMessage so Claude relays it to the user
printf '{"continue": true, "systemMessage": "💡 %s"}\n' "${tip//\"/\\\"}"
