Add Ralph CLI integration to interactive installer
Changes: - Add INSTALL_RALPH=false variable - Add select_ralph() function (Step 6: Ralph CLI Selection) - Add install_ralph() function with full Ralph CLI setup - Add MAGENTA color definition - Update step numbers: Prerequisites Check (Step 7), Claude Code Install (Step 8), Installation (Step 10) - Update perform_installation() to call install_ralph() - Update show_summary() to display Ralph CLI status - Update main() to call select_ralph() - Fix line endings (CRLF -> LF) Ralph CLI integration includes: - npm global install: @iannuttall/ralph - Auto-trigger hook: ~/.claude/hooks/ralph-auto-trigger.sh - hooks.json configuration for UserPromptSubmit - ralph-config.env for environment variables - Modes: always/agents/off Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
MAGENTA='\033[0;35m'
|
||||
CYAN='\033[0;36m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
@@ -369,13 +370,43 @@ select_hooks() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Ralph Selection
|
||||
################################################################################
|
||||
|
||||
select_ralph() {
|
||||
print_header
|
||||
echo -e "${BOLD}Step 6: Ralph CLI (Advanced - Optional)${NC}"
|
||||
echo "═══════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
echo "Ralph CLI provides autonomous agent looping (infinite iterations"
|
||||
echo "until task completion). This is an ADVANCED feature for complex"
|
||||
echo "multi-step workflows."
|
||||
echo ""
|
||||
echo " ${CYAN}• PROACTIVELY agents${NC}: Quick, single-pass coordination (built-in)"
|
||||
echo " ${CYAN}• Ralph CLI${NC}: Autonomous looping, stateful, requires installation"
|
||||
echo ""
|
||||
echo "See Step 6 in MASTER-PROMPT.md for full details."
|
||||
echo ""
|
||||
|
||||
if confirm "Install Ralph CLI for autonomous looping? (Optional)" "N"; then
|
||||
INSTALL_RALPH=true
|
||||
log_success "Ralph CLI selected"
|
||||
else
|
||||
INSTALL_RALPH=false
|
||||
log_warning "Ralph CLI skipped (using built-in PROACTIVELY agents)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Prerequisites Check
|
||||
################################################################################
|
||||
|
||||
check_prerequisites() {
|
||||
print_header
|
||||
echo -e "${BOLD}Step 6: Prerequisites Check${NC}"
|
||||
echo -e "${BOLD}Step 7: Prerequisites Check${NC}"
|
||||
echo "═══════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
@@ -436,7 +467,7 @@ check_prerequisites() {
|
||||
|
||||
install_claude_code() {
|
||||
print_header
|
||||
echo -e "${BOLD}Step 7: Claude Code Installation${NC}"
|
||||
echo -e "${BOLD}Step 8: Claude Code Installation${NC}"
|
||||
echo "═══════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
@@ -1092,9 +1123,185 @@ install_hooks() {
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Ralph CLI Installation
|
||||
################################################################################
|
||||
|
||||
install_ralph() {
|
||||
if [ "$INSTALL_RALPH" = false ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
log_info "Installing Ralph CLI..."
|
||||
|
||||
# Check if npm is available
|
||||
if ! command -v npm &> /dev/null; then
|
||||
log_error "npm not found. Cannot install Ralph CLI."
|
||||
return
|
||||
fi
|
||||
|
||||
# Install Ralph CLI globally
|
||||
if npm install -g @iannuttall/ralph 2>/dev/null; then
|
||||
log_success "Ralph CLI installed via npm"
|
||||
else
|
||||
log_warning "Ralph CLI installation failed. You can install manually later: npm install -g @iannuttall/ralph"
|
||||
return
|
||||
fi
|
||||
|
||||
# Create hooks directory
|
||||
mkdir -p "$CLAUDE_DIR/hooks"
|
||||
|
||||
# Create ralph-auto-trigger.sh script
|
||||
log_info "Creating Ralph auto-trigger hook..."
|
||||
cat > "$CLAUDE_DIR/hooks/ralph-auto-trigger.sh" << 'RALPH_HOOK_EOF'
|
||||
#!/bin/bash
|
||||
# Ralph Auto-Trigger Hook
|
||||
# Detects agent requests and manages Ralph state for autonomous looping
|
||||
|
||||
STATE_FILE="$HOME/.claude/ralph-loop.local.md"
|
||||
RALPH_MODE="${RALPH_AUTO_MODE:-agents}" # Options: always, agents, off
|
||||
|
||||
# Agent detection list (lowercase for matching)
|
||||
AGENTS=(
|
||||
"ai-engineer" "backend-architect" "devops-automator" "frontend-developer"
|
||||
"mobile-app-builder" "rapid-prototyper" "test-writer-fixer"
|
||||
"tiktok-strategist" "growth-hacker" "content-creator" "instagram-curator"
|
||||
"reddit-builder" "twitter-engager" "app-store-optimizer"
|
||||
"brand-guardian" "ui-designer" "ux-researcher" "visual-storyteller"
|
||||
"whimsy-injector" "ui-ux-pro-max"
|
||||
"feedback-synthesizer" "sprint-prioritizer" "trend-researcher"
|
||||
"experiment-tracker" "project-shipper" "studio-producer" "studio-coach"
|
||||
"analytics-reporter" "finance-tracker" "infrastructure-maintainer"
|
||||
"legal-compliance-checker" "support-responder"
|
||||
"api-tester" "performance-benchmarker" "test-results-analyzer"
|
||||
"tool-evaluator" "workflow-optimizer"
|
||||
"joker" "agent-updater"
|
||||
)
|
||||
|
||||
# Check if mode is off
|
||||
if [ "$RALPH_MODE" = "off" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Read the user prompt
|
||||
USER_PROMPT="$1"
|
||||
|
||||
# Detect agent request (case-insensitive)
|
||||
agent_detected=false
|
||||
detected_agent=""
|
||||
|
||||
for agent in "${AGENTS[@]}"; do
|
||||
if echo "$USER_PROMPT" | grep -iq "$agent"; then
|
||||
agent_detected=true
|
||||
detected_agent="$agent"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if we should trigger
|
||||
should_trigger=false
|
||||
|
||||
if [ "$RALPH_MODE" = "always" ]; then
|
||||
# Trigger on all prompts
|
||||
should_trigger=true
|
||||
elif [ "$RALPH_MODE" = "agents" ]; then
|
||||
# Only trigger on agent requests
|
||||
if [ "$agent_detected" = true ]; then
|
||||
should_trigger=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$should_trigger" = true ]; then
|
||||
# Create/update state file
|
||||
cat > "$STATE_FILE" << EOF
|
||||
# Ralph Loop State
|
||||
# Generated: $(date)
|
||||
|
||||
**User Request:**
|
||||
$USER_PROMPT
|
||||
|
||||
**Detected Agent:** $detected_agent
|
||||
**Mode:** $RALPH_MODE
|
||||
**Timestamp:** $(date -Iseconds)
|
||||
|
||||
## Context
|
||||
|
||||
This state file was automatically generated by the Ralph auto-trigger hook.
|
||||
Ralph CLI can read this file to continue autonomous looping based on the user's request.
|
||||
|
||||
## Usage
|
||||
|
||||
To run Ralph autonomously:
|
||||
\`\`\`bash
|
||||
ralph build 50 # Run 50 iterations
|
||||
\`\`\`
|
||||
|
||||
Ralph will read this state file and continue working until the task is complete.
|
||||
EOF
|
||||
|
||||
# Log the trigger (silent, no output)
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Ralph auto-triggered: mode=$RALPH_MODE, agent=$detected_agent" >> "$HOME/.claude/ralph-trigger.log" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
exit 0
|
||||
RALPH_HOOK_EOF
|
||||
|
||||
chmod +x "$CLAUDE_DIR/hooks/ralph-auto-trigger.sh"
|
||||
log_success "Ralph auto-trigger hook created"
|
||||
|
||||
# Create or update hooks.json
|
||||
log_info "Configuring hooks.json..."
|
||||
HOOKS_FILE="$CLAUDE_DIR/hooks.json"
|
||||
|
||||
if [ -f "$HOOKS_FILE" ]; then
|
||||
# Backup existing hooks.json
|
||||
cp "$HOOKS_FILE" "$HOOKS_FILE.backup.$(date +%Y%m%d-%H%M%S)"
|
||||
fi
|
||||
|
||||
# Create new hooks.json with Ralph hook
|
||||
cat > "$HOOKS_FILE" << 'HOOKS_JSON_EOF'
|
||||
{
|
||||
"description": "User hooks for Ralph auto-trigger and custom behavior",
|
||||
"hooks": {
|
||||
"UserPromptSubmit": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash",
|
||||
"args": ["/home/uroma/.claude/hooks/ralph-auto-trigger.sh", "{{userPrompt}}"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
HOOKS_JSON_EOF
|
||||
|
||||
log_success "hooks.json configured for Ralph auto-trigger"
|
||||
|
||||
# Create environment file for Ralph configuration
|
||||
cat > "$CLAUDE_DIR/ralph-config.env" << 'RALPH_ENV_EOF'
|
||||
# Ralph CLI Configuration
|
||||
# Source this file or add to your shell profile: export RALPH_AUTO_MODE=agents
|
||||
|
||||
# Ralph auto-trigger mode:
|
||||
# - always: Trigger on all prompts
|
||||
# - agents: Only trigger on agent requests (default)
|
||||
# - off: Disable auto-trigger
|
||||
export RALPH_AUTO_MODE="${RALPH_AUTO_MODE:-agents}"
|
||||
|
||||
# Ralph state file location (auto-created)
|
||||
export RALPH_STATE_FILE="$HOME/.claude/ralph-loop.local.md"
|
||||
RALPH_ENV_EOF
|
||||
|
||||
log_success "Ralph configuration saved to $CLAUDE_DIR/ralph-config.env"
|
||||
echo ""
|
||||
log_info "To enable Ralph auto-trigger, add to your shell profile:"
|
||||
echo " source ~/.claude/ralph-config.env"
|
||||
echo ""
|
||||
log_info "Ralph CLI modes: always (all prompts) | agents (agent prompts only) | off (disabled)"
|
||||
}
|
||||
|
||||
perform_installation() {
|
||||
print_header
|
||||
echo -e "${BOLD}Step 9: Installation${NC}"
|
||||
echo -e "${BOLD}Step 10: Installation${NC}"
|
||||
echo "═══════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
@@ -1107,6 +1314,7 @@ perform_installation() {
|
||||
install_mcp_tools
|
||||
install_plugins
|
||||
install_hooks
|
||||
install_ralph
|
||||
|
||||
echo ""
|
||||
log_success "Installation completed!"
|
||||
@@ -1150,6 +1358,10 @@ show_summary() {
|
||||
echo "║ • Hooks: ${GREEN}Installed${NC} ║"
|
||||
fi
|
||||
|
||||
if [ "$INSTALL_RALPH" = true ]; then
|
||||
echo "║ • Ralph CLI: ${MAGENTA}Installed (Autonomous Looping)${NC} ║"
|
||||
fi
|
||||
|
||||
echo "║ ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
@@ -1198,6 +1410,7 @@ main() {
|
||||
select_mcp_tools
|
||||
select_plugins
|
||||
select_hooks
|
||||
select_ralph
|
||||
check_prerequisites
|
||||
install_claude_code
|
||||
backup_config
|
||||
|
||||
Reference in New Issue
Block a user