Implements bd-hwmp and bd-5otr (part of epic bd-nxgk) to help AI agents automatically detect and adapt to bd upgrades. ## Changes ### Documentation (bd-hwmp) - Added "After Upgrading bd" section to AGENTS.md with step-by-step workflow - Enhanced "Pro Tips for Agents" with upgrade detection guidance - Documents bd info --whats-new and bd hooks install commands - References GitHub Discussion #239 ### Startup Hook (bd-5otr) - Created examples/startup-hooks/bd-version-check.sh - Auto-detects bd version changes via .beads/metadata.json - Shows bd info --whats-new when upgrade detected - Auto-updates outdated git hooks - Handles edge cases (no jq, not in beads project, etc.) - Created examples/startup-hooks/README.md with integration examples - Claude Code, GitHub Copilot, Cursor integration patterns - Comprehensive usage and troubleshooting guide - Updated examples/README.md with new startup-hooks section ## Impact Agents can now: - Automatically detect bd upgrades at session start - See what changed without re-reading all documentation - Keep git hooks in sync automatically - Adapt workflows based on new features Works today with zero bd code changes required! Related: #239 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
119 lines
3.8 KiB
Bash
Executable File
119 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# bd-version-check.sh - Automatic bd upgrade detection for AI agent sessions
|
|
#
|
|
# This script detects when bd (beads) has been upgraded and automatically shows
|
|
# what changed, helping AI agents adapt their workflows without manual intervention.
|
|
#
|
|
# FEATURES:
|
|
# - Detects bd version changes by comparing to last-seen version
|
|
# - Shows 'bd info --whats-new' output when upgrade detected
|
|
# - Auto-updates git hooks if outdated
|
|
# - Persists version in .beads/metadata.json
|
|
# - Zero bd code changes required - works today!
|
|
#
|
|
# INTEGRATION:
|
|
# Add this script to your AI environment's session startup:
|
|
#
|
|
# Claude Code:
|
|
# Add to .claude/hooks/session-start (if supported)
|
|
# Or manually source at beginning of work
|
|
#
|
|
# GitHub Copilot:
|
|
# Add to your shell initialization (.bashrc, .zshrc)
|
|
# Or manually run at session start
|
|
#
|
|
# Cursor:
|
|
# Add to workspace settings or shell init
|
|
#
|
|
# Generic:
|
|
# source /path/to/bd-version-check.sh
|
|
#
|
|
# USAGE:
|
|
# # Option 1: Source it (preferred)
|
|
# source examples/startup-hooks/bd-version-check.sh
|
|
#
|
|
# # Option 2: Execute it
|
|
# bash examples/startup-hooks/bd-version-check.sh
|
|
#
|
|
# REQUIREMENTS:
|
|
# - bd (beads) installed and in PATH
|
|
# - jq for JSON manipulation
|
|
# - .beads directory exists in current project
|
|
#
|
|
|
|
# Exit early if not in a beads project
|
|
if [ ! -d ".beads" ]; then
|
|
return 0 2>/dev/null || exit 0
|
|
fi
|
|
|
|
# Check if bd is installed
|
|
if ! command -v bd &> /dev/null; then
|
|
return 0 2>/dev/null || exit 0
|
|
fi
|
|
|
|
# Check if jq is installed (required for JSON manipulation)
|
|
if ! command -v jq &> /dev/null; then
|
|
echo "⚠️ bd-version-check: jq not found. Install jq to enable automatic upgrade detection."
|
|
return 0 2>/dev/null || exit 0
|
|
fi
|
|
|
|
# Get current bd version
|
|
CURRENT_VERSION=$(bd --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
|
|
|
if [ -z "$CURRENT_VERSION" ]; then
|
|
# bd command failed, skip
|
|
return 0 2>/dev/null || exit 0
|
|
fi
|
|
|
|
# Path to metadata file
|
|
METADATA_FILE=".beads/metadata.json"
|
|
|
|
# Initialize metadata.json if it doesn't exist
|
|
if [ ! -f "$METADATA_FILE" ]; then
|
|
echo '{"database": "beads.db", "jsonl_export": "beads.jsonl"}' > "$METADATA_FILE"
|
|
fi
|
|
|
|
# Read last-seen version from metadata.json
|
|
LAST_VERSION=$(jq -r '.last_bd_version // "unknown"' "$METADATA_FILE" 2>/dev/null)
|
|
|
|
# Detect version change
|
|
if [ "$CURRENT_VERSION" != "$LAST_VERSION" ] && [ "$LAST_VERSION" != "unknown" ]; then
|
|
echo ""
|
|
echo "🔄 bd upgraded: $LAST_VERSION → $CURRENT_VERSION"
|
|
echo ""
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# Show what's new
|
|
bd info --whats-new 2>/dev/null || echo "⚠️ Could not fetch what's new (run 'bd info --whats-new' manually)"
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo ""
|
|
echo "💡 Review changes above and adapt your workflow accordingly"
|
|
echo ""
|
|
fi
|
|
|
|
# Check for outdated git hooks (works even if version didn't change)
|
|
if bd hooks list 2>&1 | grep -q "outdated"; then
|
|
echo "🔧 Git hooks outdated. Updating to match bd v$CURRENT_VERSION..."
|
|
if bd hooks install 2>/dev/null; then
|
|
echo "✓ Git hooks updated successfully"
|
|
else
|
|
echo "⚠️ Failed to update git hooks. Run 'bd hooks install' manually."
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
# Update metadata.json with current version
|
|
# Use a temp file to avoid corruption if jq fails
|
|
TEMP_FILE=$(mktemp)
|
|
if jq --arg v "$CURRENT_VERSION" '.last_bd_version = $v' "$METADATA_FILE" > "$TEMP_FILE" 2>/dev/null; then
|
|
mv "$TEMP_FILE" "$METADATA_FILE"
|
|
else
|
|
# jq failed, clean up temp file
|
|
rm -f "$TEMP_FILE"
|
|
fi
|
|
|
|
# Clean exit for sourcing
|
|
return 0 2>/dev/null || exit 0
|