72 lines
2.6 KiB
Bash
Executable File
72 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Usage: ./loop.sh [plan] [max_iterations]
|
|
# Examples:
|
|
# ./loop.sh # Build mode, unlimited tasks
|
|
# ./loop.sh 20 # Build mode, max 20 tasks
|
|
# ./loop.sh plan # Plan mode, unlimited tasks
|
|
# ./loop.sh plan 5 # Plan mode, max 5 tasks
|
|
|
|
# Parse arguments
|
|
if [ "$1" = "plan" ]; then
|
|
# Plan mode
|
|
MODE="plan"
|
|
PROMPT_FILE="PROMPT_plan.md"
|
|
MAX_ITERATIONS=${2:-0}
|
|
elif [[ "$1" =~ ^[0-9]+$ ]]; then
|
|
# Build mode with max tasks
|
|
MODE="build"
|
|
PROMPT_FILE="PROMPT.md"
|
|
MAX_ITERATIONS=$1
|
|
else
|
|
# Build mode, unlimited (no arguments or invalid input)
|
|
MODE="build"
|
|
PROMPT_FILE="PROMPT_build.md"
|
|
MAX_ITERATIONS=0
|
|
fi
|
|
|
|
ITERATION=0
|
|
CURRENT_BRANCH=$(git branch --show-current)
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "Mode: $MODE"
|
|
echo "Prompt: $PROMPT_FILE"
|
|
echo "Branch: $CURRENT_BRANCH"
|
|
[ $MAX_ITERATIONS -gt 0 ] && echo "Max: $MAX_ITERATIONS iterations (number of tasks)"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# Verify prompt file exists
|
|
if [ ! -f "$PROMPT_FILE" ]; then
|
|
echo "Error: $PROMPT_FILE not found"
|
|
exit 1
|
|
fi
|
|
|
|
while true; do
|
|
if [ $MAX_ITERATIONS -gt 0 ] && [ $ITERATION -ge $MAX_ITERATIONS ]; then
|
|
echo "Reached max iterations (number of tasks): $MAX_ITERATIONS"
|
|
break
|
|
fi
|
|
|
|
# Run Ralph iteration with selected prompt
|
|
# -p: Headless mode (non-interactive, reads from stdin)
|
|
# --dangerously-skip-permissions: Auto-approve all tool calls (YOLO mode)
|
|
# --output-format=stream-json: Structured output for logging/monitoring
|
|
# --model opus: Primary agent uses Opus for complex reasoning (task selection, prioritization)
|
|
# Can use 'sonnet' in build mode for speed if plan is clear and tasks well-defined
|
|
# --verbose: Detailed execution logging
|
|
cat "$PROMPT_FILE" | claude -p \
|
|
--dangerously-skip-permissions \
|
|
--output-format=stream-json \
|
|
--verbose
|
|
|
|
# Push changes after each iteration
|
|
git push origin "$CURRENT_BRANCH" || {
|
|
echo "Failed to push. Creating remote branch..."
|
|
git push -u origin "$CURRENT_BRANCH"
|
|
}
|
|
|
|
ITERATION=$((ITERATION + 1))
|
|
echo -e "\n\n=================================================================\n"
|
|
echo -e "\n\n======================== LOOP $ITERATION ========================\n"
|
|
echo -e "\n\n=================================================================\n"
|
|
done
|