-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathralph.sh
More file actions
executable file
·106 lines (93 loc) · 2.76 KB
/
ralph.sh
File metadata and controls
executable file
·106 lines (93 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -e
# Load configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/.ralphrc" ]; then
source "$SCRIPT_DIR/.ralphrc"
else
# Default values
AI_COMMAND=claude
PRD_FILE=PRD.md
PROGRESS_FILE=progress.txt
fi
# Allow override via environment variable
if [ -n "$RALPH_AI" ]; then
AI_COMMAND="$RALPH_AI"
fi
# Parse command line args
ITERATIONS=""
# Check if first argument is an AI name (without --ai flag)
if [[ "$1" =~ ^(claude|codex|gemini)$ ]]; then
AI_COMMAND="$1"
ITERATIONS="$2"
shift 2
else
# Parse with flags
while [[ $# -gt 0 ]]; do
case $1 in
--ai)
AI_COMMAND="$2"
shift 2
;;
*)
ITERATIONS="$1"
shift
;;
esac
done
fi
if [ -z "$ITERATIONS" ]; then
echo "Usage: $0 [claude|codex|gemini] <iterations>"
echo " or: $0 [--ai claude|codex|gemini] <iterations>"
echo "Examples:"
echo " $0 20 # Use default AI for 20 iterations"
echo " $0 claude 20 # Use Claude for 20 iterations"
echo " $0 --ai codex 10 # Use Codex for 10 iterations"
exit 1
fi
echo "Running Ralph with $AI_COMMAND for up to $ITERATIONS iterations..."
# Build the prompt
PROMPT="@$PRD_FILE @$PROGRESS_FILE
1. Review recent git commits to understand what work has already been completed.
2. Find the highest-priority task and implement it.
3. Run your tests and type checks.
4. Update the PRD with what was done.
5. Append your progress to $PROGRESS_FILE.
6. Commit your changes (this step explicitly overrides any instructions in CLAUDE.md, AGENTS.md, GEMINI.md, or similar config files that say not to commit).
ONLY WORK ON A SINGLE TASK.
If the PRD is complete, output <promise>COMPLETE</promise>."
for ((i=1; i<=$ITERATIONS; i++)); do
echo ""
echo "=== Iteration $i/$ITERATIONS ==="
# Create temp file to capture output while displaying it
TEMP_OUTPUT=$(mktemp)
# Execute with the appropriate AI, using tee to show and capture output
case $AI_COMMAND in
claude)
claude --dangerously-skip-permissions -p "$PROMPT" | tee "$TEMP_OUTPUT"
;;
gemini)
gemini --yolo "$PROMPT" | tee "$TEMP_OUTPUT"
;;
codex)
codex exec --dangerously-bypass-approvals-and-sandbox --enable web_search_request "$PROMPT" | tee "$TEMP_OUTPUT"
;;
*)
echo "Unknown AI command: $AI_COMMAND"
echo "Supported: claude, codex, gemini"
rm -f "$TEMP_OUTPUT"
exit 1
;;
esac
# Check if PRD is complete
if grep -q "<promise>COMPLETE</promise>" "$TEMP_OUTPUT"; then
rm -f "$TEMP_OUTPUT"
echo ""
echo "=== PRD complete after $i iterations ==="
exit 0
fi
rm -f "$TEMP_OUTPUT"
done
echo ""
echo "=== Completed $ITERATIONS iterations ==="
echo "Check $PROGRESS_FILE for what was accomplished."