payload-contracts/scripts/execute-work-order.sh
Martin Porwoll d4e1ef1035 feat: add work-order orchestration scripts (Phase 3)
- create-work-order.sh: auto-fills CMS commit, date, contracts version
- execute-work-order.sh: updates contracts on sv-frontend, provides
  implementation instructions for Claude Code
- Updated CLAUDE.md with complete work order lifecycle documentation
- Added pnpm shortcuts: wo:create, wo:execute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 22:30:57 +00:00

118 lines
3.5 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# execute-work-order.sh — Execute a work order on sv-frontend
#
# Usage (from sv-payload):
# ./scripts/execute-work-order.sh <work-order-file> [frontend-repo]
#
# Examples:
# ./scripts/execute-work-order.sh work-orders/2026-02-15-add-stats-block.md
# ./scripts/execute-work-order.sh work-orders/2026-02-15-add-stats-block.md frontend.porwoll.de
#
# This script:
# 1. Reads the work order
# 2. SSHs to sv-frontend
# 3. Updates payload-contracts dependency
# 4. Launches Claude Code with the work order as prompt (or prints instructions)
#
# Prerequisites:
# - SSH access to sv-frontend configured (~/.ssh/config)
# - Work order committed and pushed to payload-contracts main branch
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(dirname "$SCRIPT_DIR")"
WO_FILE="${1:-}"
TARGET_REPO="${2:-}"
if [ -z "$WO_FILE" ]; then
echo "Usage: $0 <work-order-file> [frontend-repo]"
echo ""
echo "Available work orders:"
ls -1 "${ROOT}/work-orders/"*.md 2>/dev/null | grep -v _template || echo " (none)"
echo ""
echo "Example:"
echo " $0 work-orders/2026-02-15-add-stats-block.md"
echo " $0 work-orders/2026-02-15-add-stats-block.md frontend.porwoll.de"
exit 1
fi
# Resolve relative path
if [[ ! "$WO_FILE" = /* ]]; then
WO_FILE="${ROOT}/${WO_FILE}"
fi
if [ ! -f "$WO_FILE" ]; then
echo "Error: Work order not found: ${WO_FILE}"
exit 1
fi
WO_CONTENT=$(cat "$WO_FILE")
WO_NAME=$(basename "$WO_FILE")
# --- Extract affected frontends from work order ---
FRONTENDS=()
while IFS= read -r line; do
repo=$(echo "$line" | grep -oP 'frontend\.[a-z.-]+' || true)
if [ -n "$repo" ]; then
FRONTENDS+=("$repo")
fi
done <<< "$(echo "$WO_CONTENT" | grep -E '^\- \[[ x]\]')"
if [ -n "$TARGET_REPO" ]; then
FRONTENDS=("$TARGET_REPO")
fi
if [ ${#FRONTENDS[@]} -eq 0 ]; then
echo "Warning: No affected frontends found in work order."
echo "Specify a target repo: $0 $1 frontend.porwoll.de"
exit 1
fi
echo "=== Work Order: ${WO_NAME} ==="
echo "Affected frontends: ${FRONTENDS[*]}"
echo ""
# --- Process each frontend ---
for REPO in "${FRONTENDS[@]}"; do
echo "--- Processing: ${REPO} ---"
# Check if repo exists on sv-frontend
if ! ssh sv-frontend "test -d ~/\${REPO}/.git" 2>/dev/null; then
echo " Skip: ~/${REPO} not found on sv-frontend"
continue
fi
# Update contracts dependency
echo " Updating @c2s/payload-contracts..."
ssh sv-frontend "cd ~/${REPO} && pnpm update @c2s/payload-contracts 2>&1" || {
echo " Warning: pnpm update failed, trying install..."
ssh sv-frontend "cd ~/${REPO} && pnpm install 2>&1"
}
# Pull latest from contracts
ssh sv-frontend "cd ~/payload-contracts 2>/dev/null && git pull origin main 2>&1" || true
echo ""
echo " Contracts updated. To implement the work order:"
echo ""
echo " Option A — Run Claude Code on sv-frontend:"
echo " ssh sv-frontend"
echo " cd ~/${REPO}"
echo " claude"
echo " # Then paste: Implement work order ${WO_NAME}"
echo ""
echo " Option B — Remote from sv-payload:"
echo " ssh sv-frontend \"cd ~/${REPO} && claude --print 'Implement this work order: $(echo "$WO_CONTENT" | head -5 | tr '\n' ' ')...'\""
echo ""
done
echo "=== Done ==="
echo ""
echo "After implementation, verify and complete:"
echo " 1. ssh sv-frontend \"cd ~/<repo> && pnpm build\""
echo " 2. Move work order to completed/:"
echo " mv ${WO_FILE} ${ROOT}/work-orders/completed/${WO_NAME}"
echo " cd ${ROOT} && git add -A && git commit -m 'wo: complete ${WO_NAME}' && git push"