Shell
#!/bin/bash
# ═══════════════════════════════════════════════════════════════════════════════
# ID8Pipeline Pattern Tracker
# ═══════════════════════════════════════════════════════════════════════════════
# Tracks patterns across all projects to learn your development style:
# - Time spent at each stage
# - Common blockers
# - Stages frequently skipped
# - Velocity trends
#
# This data helps the pipeline give personalized guidance.
# ═══════════════════════════════════════════════════════════════════════════════
set -euo pipefail
PIPELINE_MEMORY_DIR="$HOME/.claude/pipeline-memory"
PATTERNS_FILE="$PIPELINE_MEMORY_DIR/patterns.json"
STAGE_TIMES_FILE="$PIPELINE_MEMORY_DIR/stage-times.csv"
INSIGHTS_FILE="$PIPELINE_MEMORY_DIR/insights.md"
mkdir -p "$PIPELINE_MEMORY_DIR"
# Initialize patterns file if it doesn't exist
init_patterns() {
if [[ ! -f "$PATTERNS_FILE" ]]; then
cat > "$PATTERNS_FILE" << 'EOF'
{
"projects_completed": 0,
"total_stages_cleared": 0,
"stages_skipped": {},
"average_time_per_stage": {
"1": 0, "2": 0, "3": 0, "4": 0, "5": 0,
"6": 0, "7": 0, "8": 0, "9": 0, "10": 0
},
"blockers": [],
"last_updated": ""
}
EOF
fi
if [[ ! -f "$STAGE_TIMES_FILE" ]]; then
echo "project,stage,started,completed,hours" > "$STAGE_TIMES_FILE"
fi
}
# Record when a stage is started
record_stage_start() {
local project="$1"
local stage="$2"
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
echo "$project,$stage,$timestamp,," >> "$STAGE_TIMES_FILE"
}
# Record when a stage is completed
record_stage_complete() {
local project="$1"
local stage="$2"
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
# Find the last entry for this project/stage and update it
# This is simplified - in production would be more robust
local temp_file=$(mktemp)
awk -F',' -v proj="$project" -v stg="$stage" -v ts="$timestamp" '
BEGIN { OFS="," }
NR == 1 { print; next }
$1 == proj && $2 == stg && $4 == "" {
# Calculate hours
$4 = ts
# Note: actual hour calculation would need date parsing
$5 = "TBD"
print
next
}
{ print }
' "$STAGE_TIMES_FILE" > "$temp_file"
mv "$temp_file" "$STAGE_TIMES_FILE"
}
# Analyze patterns and generate insights
generate_insights() {
init_patterns
local today=$(date "+%Y-%m-%d")
cat > "$INSIGHTS_FILE" << HEADER
# ID8Pipeline Personal Insights
> Last analyzed: $today
These insights are based on your development patterns across all tracked projects.
---
HEADER
# Count projects
local project_count=$(ls -d "$HOME/Development"/*/PIPELINE_STATUS.md 2>/dev/null | wc -l || echo "0")
echo "## Overview" >> "$INSIGHTS_FILE"
echo "" >> "$INSIGHTS_FILE"
echo "- **Projects Tracked:** $project_count" >> "$INSIGHTS_FILE"
echo "" >> "$INSIGHTS_FILE"
# Analyze stage times if we have data
if [[ -f "$STAGE_TIMES_FILE" ]] && [[ $(wc -l < "$STAGE_TIMES_FILE") -gt 1 ]]; then
echo "## Stage Duration Patterns" >> "$INSIGHTS_FILE"
echo "" >> "$INSIGHTS_FILE"
echo "| Stage | Avg Time | Your Pattern |" >> "$INSIGHTS_FILE"
echo "|-------|----------|--------------|" >> "$INSIGHTS_FILE"
# Simplified - would calculate actual averages in production
for i in {1..10}; do
local stage_name
case $i in
1) stage_name="Concept Lock" ;;
2) stage_name="Scope Fence" ;;
3) stage_name="Architecture" ;;
4) stage_name="Foundation" ;;
5) stage_name="Features" ;;
6) stage_name="Integration" ;;
7) stage_name="Polish" ;;
8) stage_name="Launch Prep" ;;
9) stage_name="Ship" ;;
10) stage_name="Iterate" ;;
esac
echo "| $i. $stage_name | TBD | Analyzing... |" >> "$INSIGHTS_FILE"
done
echo "" >> "$INSIGHTS_FILE"
fi
# Add recommendations section
cat >> "$INSIGHTS_FILE" << 'RECOMMENDATIONS'
## Recommendations
Based on your patterns (will populate as more data is collected):
1. **Watch for staleness** - Projects tend to stall after initial momentum
2. **Stage 5 is critical** - Feature Blocks often takes longest
3. **Don't skip Polish** - Stage 7 skips often lead to post-launch issues
---
## Raw Data
See `stage-times.csv` for detailed timing data.
RECOMMENDATIONS
echo "Insights generated: $INSIGHTS_FILE"
}
# Get a personalized tip based on current stage and patterns
get_personalized_tip() {
local stage="$1"
# This would query the patterns file for personalized advice
# For now, return stage-specific tips
case $stage in
1)
echo "Tip: You tend to spend time here. Focus on the one-liner before anything else."
;;
2)
echo "Tip: Be ruthless with scope. Every feature you cut now saves days later."
;;
3)
echo "Tip: Don't over-architect. A simple diagram beats a complex one."
;;
4)
echo "Tip: Deploy early, deploy often. Get the pipeline working before features."
;;
5)
echo "Tip: One feature at a time. Resist the urge to work on multiple features."
;;
6)
echo "Tip: Test the seams. Bugs hide where features meet."
;;
7)
echo "Tip: This stage is often rushed. Give it the time it deserves."
;;
8)
echo "Tip: The stranger test is real. Watch someone use it without helping."
;;
9)
echo "Tip: Ship it. Perfect is the enemy of done."
;;
10)
echo "Tip: Listen more than you build. User feedback is gold."
;;
esac
}
# ─────────────────────────────────────────────────────────────────────────────
# Entry Point
# ─────────────────────────────────────────────────────────────────────────────
case "${1:-help}" in
init)
init_patterns
echo "Patterns tracking initialized"
;;
start)
record_stage_start "${2:-}" "${3:-}"
;;
complete)
record_stage_complete "${2:-}" "${3:-}"
;;
insights)
generate_insights
;;
tip)
get_personalized_tip "${2:-1}"
;;
*)
echo "Usage: pipeline-patterns.sh {init|start|complete|insights|tip}"
echo ""
echo "Commands:"
echo " init - Initialize patterns tracking"
echo " start proj stage - Record stage start time"
echo " complete proj stg - Record stage completion"
echo " insights - Generate insights report"
echo " tip N - Get personalized tip for stage N"
;;
esac