Shell
#!/bin/bash
# ═══════════════════════════════════════════════════════════════════════════════
# ID8Pipeline Session Start Briefing
# ═══════════════════════════════════════════════════════════════════════════════
# Runs at the start of each Claude Code session to:
# - Show current pipeline status
# - Alert if work is stale
# - Provide contextual teaching for current stage
# - Suggest next actions
#
# Hook type: user-prompt-submit (runs on session start)
# ═══════════════════════════════════════════════════════════════════════════════
set -euo pipefail
PIPELINE_BRAIN="$HOME/.claude/hooks/pipeline/pipeline-brain.sh"
PIPELINE_PATTERNS="$HOME/.claude/hooks/pipeline/pipeline-patterns.sh"
STALENESS_THRESHOLD_HOURS=24
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
# Find PIPELINE_STATUS.md
find_pipeline_status() {
local dir="${PWD}"
while [[ "$dir" != "/" ]]; do
if [[ -f "$dir/PIPELINE_STATUS.md" ]]; then
echo "$dir/PIPELINE_STATUS.md"
return 0
fi
dir=$(dirname "$dir")
done
return 1
}
get_current_stage() {
local status_file="$1"
grep -oE "Current Stage: ([0-9]+)" "$status_file" 2>/dev/null | grep -oE "[0-9]+" | head -1 || echo "0"
}
get_stage_name() {
local stage_num="$1"
case $stage_num in
1) echo "Concept Lock" ;;
2) echo "Scope Fence" ;;
3) echo "Architecture Sketch" ;;
4) echo "Foundation Pour" ;;
5) echo "Feature Blocks" ;;
6) echo "Integration Pass" ;;
7) echo "Polish & Harden" ;;
8) echo "Launch Prep" ;;
9) echo "Ship" ;;
10) echo "Listen & Iterate" ;;
*) echo "Unknown" ;;
esac
}
get_checkpoint_question() {
local stage_num="$1"
case $stage_num in
1) echo "What's the one-liner?" ;;
2) echo "What are we NOT building?" ;;
3) echo "Draw me the boxes and arrows." ;;
4) echo "Can we deploy an empty shell?" ;;
5) echo "Does this feature work completely, right now?" ;;
6) echo "Do all the pieces talk to each other?" ;;
7) echo "What breaks if I do something stupid?" ;;
8) echo "Could a stranger use this without asking me questions?" ;;
9) echo "Is it live and are people using it?" ;;
10) echo "What did we learn?" ;;
*) echo "N/A" ;;
esac
}
get_stage_emoji() {
local stage_num="$1"
case $stage_num in
1) echo "🎯" ;;
2) echo "🚧" ;;
3) echo "📐" ;;
4) echo "🏗️" ;;
5) echo "🧱" ;;
6) echo "🔗" ;;
7) echo "✨" ;;
8) echo "🚀" ;;
9) echo "🎉" ;;
10) echo "👂" ;;
*) echo "📋" ;;
esac
}
calculate_staleness_hours() {
local status_file="$1"
local last_modified=$(stat -f "%m" "$status_file" 2>/dev/null || stat -c "%Y" "$status_file" 2>/dev/null)
local current_time=$(date +%s)
echo $(( (current_time - last_modified) / 3600 ))
}
# Main briefing
main() {
local status_file
if ! status_file=$(find_pipeline_status); then
# No pipeline - give a subtle hint
echo -e "${DIM}💡 No pipeline found. Use: pipeline-progress-updater.sh init${NC}"
exit 0
fi
local project=$(basename "$(dirname "$status_file")")
local stage=$(get_current_stage "$status_file")
local stage_name=$(get_stage_name "$stage")
local checkpoint=$(get_checkpoint_question "$stage")
local emoji=$(get_stage_emoji "$stage")
local hours_since=$(calculate_staleness_hours "$status_file")
# Compact but informative briefing
echo ""
echo -e "${BOLD}${CYAN}┌─────────────────────────────────────────────────────────────┐${NC}"
echo -e "${BOLD}${CYAN}│${NC} ${BOLD}ID8Pipeline: ${project}${NC}"
echo -e "${BOLD}${CYAN}├─────────────────────────────────────────────────────────────┤${NC}"
# Status line
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo -e "${BOLD}${CYAN}│${NC} ${RED}⚠ STALE (${hours_since}h)${NC} │ Stage $stage: $stage_name $emoji"
else
echo -e "${BOLD}${CYAN}│${NC} ${GREEN}✓ Active${NC} │ Stage $stage: $stage_name $emoji"
fi
echo -e "${BOLD}${CYAN}├─────────────────────────────────────────────────────────────┤${NC}"
echo -e "${BOLD}${CYAN}│${NC} ${YELLOW}Checkpoint: \"$checkpoint\"${NC}"
echo -e "${BOLD}${CYAN}└─────────────────────────────────────────────────────────────┘${NC}"
# If stale, add urgency message
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo ""
echo -e "${RED}This stage hasn't been updated in ${hours_since} hours.${NC}"
echo -e "${YELLOW}Suggested: Review PIPELINE_STATUS.md and update progress.${NC}"
fi
# Get personalized tip
if [[ -x "$PIPELINE_PATTERNS" ]]; then
echo ""
echo -e "${DIM}$($PIPELINE_PATTERNS tip "$stage")${NC}"
fi
echo ""
# Log session start
if [[ -x "$PIPELINE_BRAIN" ]]; then
"$PIPELINE_BRAIN" log "Session started at Stage $stage" 2>/dev/null || true
fi
}
main "$@"