Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions ralph.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash
# Ralph Wiggum - Long-running AI agent loop
# Usage: ./ralph.sh [--tool amp|claude] [max_iterations]
# Usage: ./ralph.sh [--tool amp|claude] [--model <model>] [--effort <level>] [max_iterations]

set -e

# Parse arguments
TOOL="amp" # Default to amp for backwards compatibility
MODEL="" # Empty = use claude CLI default
EFFORT="" # Empty = use claude CLI default (low|medium|high|xhigh|max)
MAX_ITERATIONS=10

while [[ $# -gt 0 ]]; do
Expand All @@ -18,6 +20,22 @@ while [[ $# -gt 0 ]]; do
TOOL="${1#*=}"
shift
;;
--model)
MODEL="$2"
shift 2
;;
--model=*)
MODEL="${1#*=}"
shift
;;
--effort)
EFFORT="$2"
shift 2
;;
--effort=*)
EFFORT="${1#*=}"
shift
;;
*)
# Assume it's max_iterations if it's a number
if [[ "$1" =~ ^[0-9]+$ ]]; then
Expand All @@ -33,6 +51,12 @@ if [[ "$TOOL" != "amp" && "$TOOL" != "claude" ]]; then
echo "Error: Invalid tool '$TOOL'. Must be 'amp' or 'claude'."
exit 1
fi

# Validate effort choice
if [[ -n "$EFFORT" && ! "$EFFORT" =~ ^(low|medium|high|xhigh|max)$ ]]; then
echo "Error: Invalid effort '$EFFORT'. Must be one of: low, medium, high, xhigh, max."
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PRD_FILE="$SCRIPT_DIR/prd.json"
PROGRESS_FILE="$SCRIPT_DIR/progress.txt"
Expand Down Expand Up @@ -79,20 +103,23 @@ if [ ! -f "$PROGRESS_FILE" ]; then
echo "---" >> "$PROGRESS_FILE"
fi

echo "Starting Ralph - Tool: $TOOL - Max iterations: $MAX_ITERATIONS"
echo "Starting Ralph - Tool: $TOOL - Model: ${MODEL:-default} - Effort: ${EFFORT:-default} - Max iterations: $MAX_ITERATIONS"

for i in $(seq 1 $MAX_ITERATIONS); do
echo ""
echo "==============================================================="
echo " Ralph Iteration $i of $MAX_ITERATIONS ($TOOL)"
echo " Ralph Iteration $i of $MAX_ITERATIONS ($TOOL${MODEL:+, model=$MODEL}${EFFORT:+, effort=$EFFORT})"
echo "==============================================================="

# Run the selected tool with the ralph prompt
if [[ "$TOOL" == "amp" ]]; then
OUTPUT=$(cat "$SCRIPT_DIR/prompt.md" | amp --dangerously-allow-all 2>&1 | tee /dev/stderr) || true
else
# Claude Code: use --dangerously-skip-permissions for autonomous operation, --print for output
OUTPUT=$(claude --dangerously-skip-permissions --print < "$SCRIPT_DIR/CLAUDE.md" 2>&1 | tee /dev/stderr) || true
CLAUDE_ARGS=(--dangerously-skip-permissions --print)
[[ -n "$MODEL" ]] && CLAUDE_ARGS+=(--model "$MODEL")
[[ -n "$EFFORT" ]] && CLAUDE_ARGS+=(--effort "$EFFORT")
OUTPUT=$(claude "${CLAUDE_ARGS[@]}" < "$SCRIPT_DIR/CLAUDE.md" 2>&1 | tee /dev/stderr) || true
fi

# Check for completion signal
Expand Down