Shell
#!/bin/bash
# ═══════════════════════════════════════════════════════════════════════════════
# ID8Pipeline Brain - The Living Pipeline Core
# ═══════════════════════════════════════════════════════════════════════════════
# This is the central intelligence of the pipeline system.
# It detects state, calculates staleness, and provides contextual guidance.
#
# Usage:
# ./pipeline-brain.sh status - Get full pipeline status
# ./pipeline-brain.sh stage - Get current stage only
# ./pipeline-brain.sh staleness - Check if work is stale
# ./pipeline-brain.sh next-action - Get recommended next action
# ./pipeline-brain.sh teach - Get contextual teaching for current stage
# ./pipeline-brain.sh log <message> - Log activity to pipeline history
# ═══════════════════════════════════════════════════════════════════════════════
set -euo pipefail
# Configuration
STALENESS_THRESHOLD_HOURS=24 # 1 day
PIPELINE_MEMORY_DIR="$HOME/.claude/pipeline-memory"
PIPELINE_LOG="$PIPELINE_MEMORY_DIR/activity.log"
PATTERNS_FILE="$PIPELINE_MEMORY_DIR/patterns.json"
# 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'
NC='\033[0m'
# Ensure directories exist
mkdir -p "$PIPELINE_MEMORY_DIR"
# ─────────────────────────────────────────────────────────────────────────────
# Stage Teaching Content - Contextual education for each stage
# ─────────────────────────────────────────────────────────────────────────────
get_stage_teaching() {
local stage="$1"
case $stage in
1)
echo ""
echo -e "${CYAN}★ Stage 1: Concept Lock - Why This Matters${NC}"
echo ""
echo "The one-liner forces clarity. If you can't explain it in one sentence,"
echo "you don't understand it yet. This isn't about marketing—it's about focus."
echo ""
echo -e "${YELLOW}Common Pitfalls:${NC}"
echo "• Too vague: \"A platform for productivity\" (what does that mean?)"
echo "• Too ambitious: \"An AI that replaces all software\" (scope creep begins here)"
echo "• Feature-focused: \"A todo app with reminders\" (describes HOW, not WHY)"
echo ""
echo -e "${GREEN}Good Examples:${NC}"
echo "• \"Helps freelancers get paid faster by automating invoice follow-ups\""
echo "• \"Lets parents track school photos without downloading another app\""
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"What's the one-liner?\""
;;
2)
echo ""
echo -e "${CYAN}★ Stage 2: Scope Fence - Why This Matters${NC}"
echo ""
echo "The 'not yet' list is more important than the 'yes' list. Every feature"
echo "you exclude is energy saved for the features that matter."
echo ""
echo -e "${YELLOW}The 5-Feature Rule:${NC}"
echo "If you can't get v1 down to 5 core features, you're building too much."
echo "Each additional feature multiplies complexity, not adds to it."
echo ""
echo -e "${GREEN}Power Move:${NC}"
echo "Write your 'not yet' list FIRST. Get excited about v2 features, then"
echo "consciously set them aside. This creates motivation for shipping v1."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"What are we NOT building?\""
;;
3)
echo ""
echo -e "${CYAN}★ Stage 3: Architecture Sketch - Why This Matters${NC}"
echo ""
echo "This isn't about picking the perfect stack—it's about seeing the system"
echo "as a whole before writing code. Bad architecture decisions compound."
echo ""
echo -e "${YELLOW}Key Questions:${NC}"
echo "• Where does data live? How does it flow?"
echo "• What's the minimal stack that works?"
echo "• What will be painful to change later?"
echo ""
echo -e "${GREEN}Sketch, Don't Plan:${NC}"
echo "Boxes and arrows on paper beat detailed documents. You're building"
echo "intuition, not a contract. The sketch should fit on one page."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Draw me the boxes and arrows.\""
;;
4)
echo ""
echo -e "${CYAN}★ Stage 4: Foundation Pour - Why This Matters${NC}"
echo ""
echo "This is the 'can we deploy nothing' test. If your empty shell can't"
echo "reach production, you'll hit deployment bugs at the worst time."
echo ""
echo -e "${YELLOW}Must-Haves:${NC}"
echo "• CI/CD pipeline that deploys on push"
echo "• Database connected and migrating"
echo "• Auth flow working (even if basic)"
echo "• Environment variables flowing"
echo ""
echo -e "${GREEN}The Empty Shell Deploy:${NC}"
echo "Deploy a page that says 'Coming Soon'. This proves your entire"
echo "infrastructure works before you add complexity."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Can we deploy an empty shell?\""
;;
5)
echo ""
echo -e "${CYAN}★ Stage 5: Feature Blocks - Why This Matters${NC}"
echo ""
echo "Vertical slices beat horizontal layers. Build one complete feature"
echo "before starting another. This keeps momentum and proves value early."
echo ""
echo -e "${YELLOW}What 'Complete' Means:${NC}"
echo "• UI exists and works"
echo "• Backend handles the request"
echo "• Data persists correctly"
echo "• Errors are caught"
echo "• Edge cases considered"
echo ""
echo -e "${GREEN}The Demo Test:${NC}"
echo "After each feature, you should be able to demo it to someone."
echo "If you can't demo it, it's not done."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Does this feature work completely, right now?\""
;;
6)
echo ""
echo -e "${CYAN}★ Stage 6: Integration Pass - Why This Matters${NC}"
echo ""
echo "Individual features working doesn't mean they work together."
echo "This stage catches the gaps between your building blocks."
echo ""
echo -e "${YELLOW}Look For:${NC}"
echo "• State inconsistencies between features"
echo "• Data that doesn't flow where expected"
echo "• UX discontinuities (jarring transitions)"
echo "• Race conditions and timing issues"
echo ""
echo -e "${GREEN}Integration Testing:${NC}"
echo "Write tests that cross feature boundaries. The bugs are in the seams."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Do all the pieces talk to each other?\""
;;
7)
echo ""
echo -e "${CYAN}★ Stage 7: Polish & Harden - Why This Matters${NC}"
echo ""
echo "This is where good products become great products. Every loading"
echo "state, error message, and edge case is a user's experience."
echo ""
echo -e "${YELLOW}The Stupid User Test:${NC}"
echo "• What happens if I double-click everything?"
echo "• What if I'm offline?"
echo "• What if my session expires mid-action?"
echo "• What if I hit back/forward/refresh?"
echo ""
echo -e "${GREEN}Polish Checklist:${NC}"
echo "Loading states, empty states, error states, success feedback,"
echo "keyboard navigation, mobile responsiveness."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"What breaks if I do something stupid?\""
;;
8)
echo ""
echo -e "${CYAN}★ Stage 8: Launch Prep - Why This Matters${NC}"
echo ""
echo "The product is ready, but is the launch? This stage is about"
echo "everything outside the code."
echo ""
echo -e "${YELLOW}The Stranger Test:${NC}"
echo "Give the URL to someone who's never seen it. Watch them without"
echo "helping. Every question they ask is a gap in your onboarding."
echo ""
echo -e "${GREEN}Launch Checklist:${NC}"
echo "• Landing page that explains the value"
echo "• Onboarding that doesn't need instructions"
echo "• Analytics to learn what users actually do"
echo "• Way for users to give feedback"
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Could a stranger use this without asking me questions?\""
;;
9)
echo ""
echo -e "${CYAN}★ Stage 9: Ship - Why This Matters${NC}"
echo ""
echo "Shipping is a skill. The longer you wait, the harder it gets."
echo "A shipped product beats a perfect product that never launches."
echo ""
echo -e "${YELLOW}Ship Mindset:${NC}"
echo "• Done is better than perfect"
echo "• You can iterate after launch"
echo "• Real user feedback > your assumptions"
echo "• The goal is learning, not perfection"
echo ""
echo -e "${GREEN}Ship Actions:${NC}"
echo "• Deploy to production"
echo "• Announce it (even to a small audience)"
echo "• Turn on monitoring"
echo "• Be ready to respond"
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"Is it live and are people using it?\""
;;
10)
echo ""
echo -e "${CYAN}★ Stage 10: Listen & Iterate - Why This Matters${NC}"
echo ""
echo "The product is live—now the real learning begins. User behavior"
echo "will surprise you. That's the point."
echo ""
echo -e "${YELLOW}Listen For:${NC}"
echo "• What features are actually used?"
echo "• Where do users get stuck?"
echo "• What do they ask for?"
echo "• What do they ignore?"
echo ""
echo -e "${GREEN}Iterate Wisely:${NC}"
echo "Not every request deserves action. Look for patterns."
echo "One user's request is an opinion. Ten users' request is data."
echo ""
echo -e "${MAGENTA}Your Checkpoint:${NC} \"What did we learn?\""
;;
*)
echo "No teaching content for stage $stage"
;;
esac
}
# ─────────────────────────────────────────────────────────────────────────────
# Helper Functions
# ─────────────────────────────────────────────────────────────────────────────
find_pipeline_status() {
# Search for PIPELINE_STATUS.md in current directory and up
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_project_name() {
local status_file="$1"
local project_dir=$(dirname "$status_file")
basename "$project_dir"
}
get_current_stage() {
local status_file="$1"
# Look for "Current Stage: X" pattern
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 "No checkpoint defined" ;;
esac
}
get_last_activity_time() {
local status_file="$1"
# Get last modified time of PIPELINE_STATUS.md
if [[ -f "$status_file" ]]; then
stat -f "%m" "$status_file" 2>/dev/null || stat -c "%Y" "$status_file" 2>/dev/null || echo "0"
else
echo "0"
fi
}
calculate_staleness_hours() {
local last_activity="$1"
local current_time=$(date +%s)
local diff=$((current_time - last_activity))
echo $((diff / 3600))
}
is_stale() {
local status_file="$1"
local last_activity=$(get_last_activity_time "$status_file")
local hours_since=$(calculate_staleness_hours "$last_activity")
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
return 0 # true, is stale
else
return 1 # false, not stale
fi
}
log_activity() {
local message="$1"
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
local project=$(basename "$PWD")
echo "[$timestamp] [$project] $message" >> "$PIPELINE_LOG"
}
# ─────────────────────────────────────────────────────────────────────────────
# Main Commands
# ─────────────────────────────────────────────────────────────────────────────
cmd_status() {
local status_file
if ! status_file=$(find_pipeline_status); then
echo -e "${RED}No PIPELINE_STATUS.md found${NC}"
echo "Create one from the template: ~/.claude/PIPELINE_STATUS_TEMPLATE.md"
return 1
fi
local project=$(get_project_name "$status_file")
local stage=$(get_current_stage "$status_file")
local stage_name=$(get_stage_name "$stage")
local checkpoint=$(get_checkpoint_question "$stage")
local last_activity=$(get_last_activity_time "$status_file")
local hours_since=$(calculate_staleness_hours "$last_activity")
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD} ID8Pipeline Status: ${CYAN}$project${NC}"
echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e " ${BOLD}Current Stage:${NC} $stage - $stage_name"
echo ""
echo -e " ${BOLD}Next Checkpoint:${NC}"
echo -e " ${YELLOW}\"$checkpoint\"${NC}"
echo ""
# Staleness indicator
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo -e " ${RED}⚠ STALE: ${hours_since}h since last update${NC}"
echo -e " ${YELLOW}→ This stage needs attention!${NC}"
else
echo -e " ${GREEN}✓ Active: Last updated ${hours_since}h ago${NC}"
fi
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
# Log this status check
log_activity "Status check: Stage $stage ($stage_name)"
}
cmd_stage() {
local status_file
if ! status_file=$(find_pipeline_status); then
echo "0"
return 1
fi
get_current_stage "$status_file"
}
cmd_staleness() {
local status_file
if ! status_file=$(find_pipeline_status); then
echo "no_pipeline"
return 1
fi
local last_activity=$(get_last_activity_time "$status_file")
local hours_since=$(calculate_staleness_hours "$last_activity")
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo "stale:${hours_since}h"
return 0
else
echo "active:${hours_since}h"
return 1
fi
}
cmd_next_action() {
local status_file
if ! status_file=$(find_pipeline_status); then
echo "Create PIPELINE_STATUS.md from template"
return 1
fi
local stage=$(get_current_stage "$status_file")
local stage_name=$(get_stage_name "$stage")
local checkpoint=$(get_checkpoint_question "$stage")
# Check staleness
local last_activity=$(get_last_activity_time "$status_file")
local hours_since=$(calculate_staleness_hours "$last_activity")
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo -e "${RED}[STALE ${hours_since}h]${NC} Stage $stage: $stage_name"
echo ""
echo "Suggested actions:"
echo " 1. Review current stage progress in PIPELINE_STATUS.md"
echo " 2. Answer checkpoint: \"$checkpoint\""
echo " 3. Update PIPELINE_STATUS.md with current status"
else
echo "Stage $stage: $stage_name"
echo ""
echo "Checkpoint to clear: \"$checkpoint\""
fi
}
cmd_teach() {
local status_file
if ! status_file=$(find_pipeline_status); then
echo "No pipeline found. Here's the overview:"
echo ""
echo "The ID8Pipeline has 10 stages:"
echo " 1. Concept Lock - Define the problem"
echo " 2. Scope Fence - Set boundaries"
echo " 3. Architecture - Design the system"
echo " 4. Foundation - Build scaffolding"
echo " 5. Feature Blocks - Build features"
echo " 6. Integration - Connect pieces"
echo " 7. Polish - Handle edge cases"
echo " 8. Launch Prep - Prepare for users"
echo " 9. Ship - Go live"
echo " 10. Iterate - Learn and improve"
return 0
fi
local stage=$(get_current_stage "$status_file")
get_stage_teaching "$stage"
}
cmd_log() {
local message="$1"
log_activity "$message"
echo "Logged: $message"
}
cmd_briefing() {
# Full session-start briefing
echo ""
echo -e "${BOLD}${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BOLD}${CYAN}║ ID8Pipeline Session Briefing ║${NC}"
echo -e "${BOLD}${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
local status_file
if ! status_file=$(find_pipeline_status); then
echo -e "${YELLOW}⚠ No active pipeline found in this project${NC}"
echo ""
echo "To start a new pipeline:"
echo " cp ~/.claude/PIPELINE_STATUS_TEMPLATE.md ./PIPELINE_STATUS.md"
echo ""
return 0
fi
local project=$(get_project_name "$status_file")
local stage=$(get_current_stage "$status_file")
local stage_name=$(get_stage_name "$stage")
local checkpoint=$(get_checkpoint_question "$stage")
local last_activity=$(get_last_activity_time "$status_file")
local hours_since=$(calculate_staleness_hours "$last_activity")
echo -e " ${BOLD}Project:${NC} $project"
echo -e " ${BOLD}Stage:${NC} $stage - $stage_name"
if [[ $hours_since -ge $STALENESS_THRESHOLD_HOURS ]]; then
echo -e " ${BOLD}Status:${NC} ${RED}Stale (${hours_since}h)${NC}"
else
echo -e " ${BOLD}Status:${NC} ${GREEN}Active${NC}"
fi
echo ""
echo -e " ${BOLD}Your Focus:${NC}"
echo -e " ${YELLOW}\"$checkpoint\"${NC}"
echo ""
# Show brief teaching
echo -e "${BLUE}────────────────────────────────────────────────────────────────${NC}"
get_stage_teaching "$stage" | head -15
echo ""
# Log briefing
log_activity "Session started: Stage $stage"
}
# ─────────────────────────────────────────────────────────────────────────────
# Entry Point
# ─────────────────────────────────────────────────────────────────────────────
case "${1:-status}" in
status) cmd_status ;;
stage) cmd_stage ;;
staleness) cmd_staleness ;;
next-action) cmd_next_action ;;
teach) cmd_teach ;;
log) cmd_log "${2:-Activity logged}" ;;
briefing) cmd_briefing ;;
*)
echo "Usage: pipeline-brain.sh {status|stage|staleness|next-action|teach|log|briefing}"
exit 1
;;
esac