#!/usr/bin/env bash set -euo pipefail # Sync selected skills from upstream (github.com/obra/superpowers) # Usage: ./scripts/sync-upstream.sh [--dry-run] REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$REPO_ROOT" DRY_RUN=${DRY_RUN:-false} if [[ "${1:-}" == "--dry-run" ]]; then DRY_RUN=true fi SKILLS=( systematic-debugging test-driven-development verification-before-completion writing-plans requesting-code-review receiving-code-review finishing-a-development-branch ) echo "Fetching upstream..." git fetch upstream --depth=1 UPSTREAM_REF="upstream/main" CURRENT_REF="HEAD" CHANGED=false for skill in "${SKILLS[@]}"; do echo "" echo "=== Checking skills/$skill ===" # Get list of files that differ diff_files=$(git diff --name-only "$CURRENT_REF" "$UPSTREAM_REF" -- "skills/$skill" 2>/dev/null || true) if [[ -z "$diff_files" ]]; then echo " Up to date" continue fi echo " Changes detected:" echo "$diff_files" | sed 's/^/ /' if [[ "$DRY_RUN" == true ]]; then echo " (dry-run, skipping copy)" CHANGED=true continue fi # Checkout the entire skill directory from upstream git checkout "$UPSTREAM_REF" -- "skills/$skill" echo " Merged from upstream" CHANGED=true done if [[ "$CHANGED" == false ]]; then echo "" echo "All skills up to date. Nothing to do." exit 0 fi if [[ "$DRY_RUN" == true ]]; then echo "" echo "Dry run complete. Run without --dry-run to apply changes." exit 0 fi # Stage everything in skills/ git add -A skills/ if git diff --cached --quiet; then echo "" echo "No changes to commit after merge." exit 0 fi echo "" echo "Changes staged. Commit with:" echo " git commit -m 'Sync skills from obra/superpowers upstream (v$(git describe --tags "$UPSTREAM_REF" 2>/dev/null || echo "$(git rev-parse --short "$UPSTREAM_REF")"))'"