|
| 1 | +#!/bin/bash |
| 2 | +# Ralph Wiggum: Initialize Ralph in a project |
| 3 | +# Sets up Ralph tracking for CLI mode |
| 4 | + |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +SKILL_DIR="$(dirname "$SCRIPT_DIR")" |
| 9 | + |
| 10 | +echo "═══════════════════════════════════════════════════════════════════" |
| 11 | +echo "🐛 Ralph Wiggum Initialization" |
| 12 | +echo "═══════════════════════════════════════════════════════════════════" |
| 13 | +echo "" |
| 14 | + |
| 15 | +# Check if we're in a git repo |
| 16 | +if ! git rev-parse --git-dir > /dev/null 2>&1; then |
| 17 | + echo "⚠️ Warning: Not in a git repository." |
| 18 | + echo " Ralph works best with git for state persistence." |
| 19 | + echo "" |
| 20 | + read -p "Continue anyway? [y/N] " -n 1 -r |
| 21 | + echo |
| 22 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +fi |
| 26 | + |
| 27 | +# Check for cursor-agent CLI |
| 28 | +if ! command -v cursor-agent &> /dev/null; then |
| 29 | + echo "⚠️ Warning: cursor-agent CLI not found." |
| 30 | + echo " Install via: curl https://cursor.com/install -fsS | bash" |
| 31 | + echo "" |
| 32 | +fi |
| 33 | + |
| 34 | +# Create directories |
| 35 | +mkdir -p .ralph |
| 36 | +mkdir -p .cursor/ralph-scripts |
| 37 | + |
| 38 | +# ============================================================================= |
| 39 | +# CREATE RALPH_TASK.md IF NOT EXISTS |
| 40 | +# ============================================================================= |
| 41 | + |
| 42 | +if [[ ! -f "RALPH_TASK.md" ]]; then |
| 43 | + echo "📝 Creating RALPH_TASK.md template..." |
| 44 | + if [[ -f "$SKILL_DIR/assets/RALPH_TASK_TEMPLATE.md" ]]; then |
| 45 | + cp "$SKILL_DIR/assets/RALPH_TASK_TEMPLATE.md" RALPH_TASK.md |
| 46 | + else |
| 47 | + cat > RALPH_TASK.md << 'EOF' |
| 48 | +--- |
| 49 | +task: Your task description here |
| 50 | +test_command: "npm test" |
| 51 | +--- |
| 52 | +
|
| 53 | +# Task |
| 54 | +
|
| 55 | +Describe what you want to accomplish. |
| 56 | +
|
| 57 | +## Success Criteria |
| 58 | +
|
| 59 | +1. [ ] First thing to complete |
| 60 | +2. [ ] Second thing to complete |
| 61 | +3. [ ] Third thing to complete |
| 62 | +
|
| 63 | +## Context |
| 64 | +
|
| 65 | +Any additional context the agent should know. |
| 66 | +EOF |
| 67 | + fi |
| 68 | + echo " Edit RALPH_TASK.md to define your task." |
| 69 | +else |
| 70 | + echo "✓ RALPH_TASK.md already exists" |
| 71 | +fi |
| 72 | + |
| 73 | +# ============================================================================= |
| 74 | +# INITIALIZE STATE FILES |
| 75 | +# ============================================================================= |
| 76 | + |
| 77 | +echo "📁 Initializing .ralph/ directory..." |
| 78 | + |
| 79 | +cat > .ralph/guardrails.md << 'EOF' |
| 80 | +# Ralph Guardrails (Signs) |
| 81 | +
|
| 82 | +> Lessons learned from past failures. READ THESE BEFORE ACTING. |
| 83 | +
|
| 84 | +## Core Signs |
| 85 | +
|
| 86 | +### Sign: Read Before Writing |
| 87 | +- **Trigger**: Before modifying any file |
| 88 | +- **Instruction**: Always read the existing file first |
| 89 | +- **Added after**: Core principle |
| 90 | +
|
| 91 | +### Sign: Test After Changes |
| 92 | +- **Trigger**: After any code change |
| 93 | +- **Instruction**: Run tests to verify nothing broke |
| 94 | +- **Added after**: Core principle |
| 95 | +
|
| 96 | +### Sign: Commit Checkpoints |
| 97 | +- **Trigger**: Before risky changes |
| 98 | +- **Instruction**: Commit current working state first |
| 99 | +- **Added after**: Core principle |
| 100 | +
|
| 101 | +--- |
| 102 | +
|
| 103 | +## Learned Signs |
| 104 | +
|
| 105 | +(Signs added from observed failures will appear below) |
| 106 | +
|
| 107 | +EOF |
| 108 | + |
| 109 | +cat > .ralph/progress.md << 'EOF' |
| 110 | +# Progress Log |
| 111 | +
|
| 112 | +> Updated by the agent after significant work. |
| 113 | +
|
| 114 | +## Summary |
| 115 | +
|
| 116 | +- Iterations completed: 0 |
| 117 | +- Current status: Initialized |
| 118 | +
|
| 119 | +## How This Works |
| 120 | +
|
| 121 | +Progress is tracked in THIS FILE, not in LLM context. |
| 122 | +When context is rotated (fresh agent), the new agent reads this file. |
| 123 | +This is how Ralph maintains continuity across iterations. |
| 124 | +
|
| 125 | +## Session History |
| 126 | +
|
| 127 | +EOF |
| 128 | + |
| 129 | +cat > .ralph/errors.log << 'EOF' |
| 130 | +# Error Log |
| 131 | +
|
| 132 | +> Failures detected by stream-parser. Use to update guardrails. |
| 133 | +
|
| 134 | +EOF |
| 135 | + |
| 136 | +cat > .ralph/activity.log << 'EOF' |
| 137 | +# Activity Log |
| 138 | +
|
| 139 | +> Real-time tool call logging from stream-parser. |
| 140 | +
|
| 141 | +EOF |
| 142 | + |
| 143 | +echo "0" > .ralph/.iteration |
| 144 | + |
| 145 | +# ============================================================================= |
| 146 | +# INSTALL SCRIPTS |
| 147 | +# ============================================================================= |
| 148 | + |
| 149 | +echo "📦 Installing scripts..." |
| 150 | + |
| 151 | +# Copy scripts |
| 152 | +cp "$SKILL_DIR/scripts/"*.sh .cursor/ralph-scripts/ 2>/dev/null || true |
| 153 | +chmod +x .cursor/ralph-scripts/*.sh 2>/dev/null || true |
| 154 | + |
| 155 | +echo "✓ Scripts installed to .cursor/ralph-scripts/" |
| 156 | + |
| 157 | +# ============================================================================= |
| 158 | +# UPDATE .gitignore |
| 159 | +# ============================================================================= |
| 160 | + |
| 161 | +if [[ -f ".gitignore" ]]; then |
| 162 | + # Don't gitignore .ralph/ - we want it tracked for state persistence |
| 163 | + if ! grep -q "ralph-config.json" .gitignore; then |
| 164 | + echo "" >> .gitignore |
| 165 | + echo "# Ralph config (may contain API keys)" >> .gitignore |
| 166 | + echo ".cursor/ralph-config.json" >> .gitignore |
| 167 | + fi |
| 168 | + echo "✓ Updated .gitignore" |
| 169 | +else |
| 170 | + cat > .gitignore << 'EOF' |
| 171 | +# Ralph config (may contain API keys) |
| 172 | +.cursor/ralph-config.json |
| 173 | +EOF |
| 174 | + echo "✓ Created .gitignore" |
| 175 | +fi |
| 176 | + |
| 177 | +# ============================================================================= |
| 178 | +# SUMMARY |
| 179 | +# ============================================================================= |
| 180 | + |
| 181 | +echo "" |
| 182 | +echo "═══════════════════════════════════════════════════════════════════" |
| 183 | +echo "✅ Ralph initialized!" |
| 184 | +echo "═══════════════════════════════════════════════════════════════════" |
| 185 | +echo "" |
| 186 | +echo "Files created:" |
| 187 | +echo " • RALPH_TASK.md - Define your task here" |
| 188 | +echo " • .ralph/guardrails.md - Lessons learned (agent updates this)" |
| 189 | +echo " • .ralph/progress.md - Progress log (agent updates this)" |
| 190 | +echo " • .ralph/activity.log - Tool call log (parser updates this)" |
| 191 | +echo " • .ralph/errors.log - Failure log (parser updates this)" |
| 192 | +echo "" |
| 193 | +echo "Next steps:" |
| 194 | +echo " 1. Edit RALPH_TASK.md to define your task and criteria" |
| 195 | +echo " 2. Run: ./scripts/ralph-loop.sh" |
| 196 | +echo " (or: .cursor/ralph-scripts/ralph-loop.sh)" |
| 197 | +echo "" |
| 198 | +echo "The agent will work autonomously, rotating context as needed." |
| 199 | +echo "Monitor progress: tail -f .ralph/activity.log" |
| 200 | +echo "" |
| 201 | +echo "Learn more: https://ghuntley.com/ralph/" |
| 202 | +echo "═══════════════════════════════════════════════════════════════════" |
0 commit comments