Initial Ralph scaffold for ralph-vibe

This commit is contained in:
Debian
2026-01-10 11:59:27 +00:00
commit 688cfe57ed
9 changed files with 3469 additions and 0 deletions

881
docs/framework.md Normal file
View File

@@ -0,0 +1,881 @@
# The Ralph Method: Comprehensive Framework for 100% Vibe-Coded Greenfield Projects
## Executive Summary
The Ralph Method is an iterative AI development methodology that runs autonomous coding agents in persistent loops until task completion. Named after Ralph Wiggum from The Simpsons—perpetually confused but never stopping—it embodies the philosophy: **"Better to fail predictably than succeed unpredictably."**
Core principle: Iteration beats perfection. The agent sees previous work via git history and modified files, learns from it, and iteratively improves.
---
## Part 1: Philosophy and Prerequisites
### The Ralph Mindset
- **Deterministically bad in an undeterministic world**: Failures are predictable and informative
- **Operator skill matters**: Success depends on writing good prompts, not just having a good model
- **LLMs are mirrors of operator skill**: The quality of output reflects the quality of input
- **Faith in eventual consistency**: Ralph will test you. Each failure tunes the system like a guitar
### Prerequisites
1. **Claude Code** installed and configured
2. **Git** initialized in project directory
3. **jq** installed (required dependency on Windows/Git Bash)
4. **Clear success criteria** for your project
5. **Cost awareness**: Opus 4.5 burns $15-75/hour on large contexts
---
## Part 2: PRD Structure for Ralph Consumption
Traditional PRDs must be converted to machine-parseable format. Create `PROMPT.md` in your project root.
### PRD Template
```markdown
# Project: [NAME]
## Objective
[One sentence describing the end state]
## Application Type
[Web app | Desktop app | CLI tool | Library | Mobile app | Other]
## Architecture
- Interface types: [REST API | GraphQL | IPC | Module boundaries | CLI | File formats]
- Persistence: [Remote DB | Local DB | File-based | In-memory | None]
- Deployment: [Cloud | Self-hosted | Desktop installer | Package registry | App store]
## Tech Stack
- Language: [X]
- Framework: [X]
- Database/Storage: [X]
- Testing: [X]
- CI: [X]
## Completion Criteria
All of the following must be true:
1. Build command passes with zero errors
2. Test command passes with >80% coverage
3. Lint command passes
4. All features documented in README.md
5. [App-type specific criteria, e.g.:]
- Web: Docker compose brings up working stack
- Desktop: Installers build for all target platforms
- CLI: Binary runs and --help works
- Library: Package publishes to registry (dry-run)
Output `<promise>PROJECT_COMPLETE</promise>` when all criteria met.
## Phase 1: Foundation
- [ ] Initialize project structure
- [ ] Set up CI/linting/formatting
- [ ] Create data layer (DB schema | file handlers | state management)
- [ ] Write failing tests for core models
## Phase 2: Core [Features | UI | Commands | API]
[Adapted to app type]
- [ ] Feature A
- Acceptance: [binary criterion]
- [ ] Feature B
- Acceptance: [binary criterion]
## Phase 3: [Integration | System | I/O]
[Adapted to app type:]
- Web: External services, auth, error handling
- Desktop: System integration, file watching, native APIs
- CLI: Input parsing, output formatting, piping support
- Library: Edge cases, error handling, type exports
## Phase 4: [Polish | Packaging | Publishing]
[Adapted to app type:]
- Web: Documentation, performance, deployment config
- Desktop: Installers, auto-update, icons, signing
- CLI: Man pages, shell completions, distribution
- Library: API docs, examples, changelog, publishing
## Constraints
- No external API calls without mocking in tests
- All functions must have docstrings/JSDoc
- [Language-specific, e.g., No `any` types for TypeScript]
- [Additional constraints]
## Abort Conditions
If any of these occur, output `<promise>ABORT_BLOCKED</promise>`:
- Cannot resolve circular dependency after 5 attempts
- External service unavailable after 3 retries
- Architectural issue that requires human decision
- After 15 iterations if not fixed, document blocking issues
```
### PRD Conversion Rules
| Traditional PRD Element | Ralph Format |
|------------------------|--------------|
| User stories | Concrete acceptance tests |
| "Should support X" | Specific test file that must pass |
| Architecture diagrams | File structure specification |
| "Nice to have" | Remove entirely or move to Phase 4 |
| Ambiguous requirements | Binary pass/fail criteria |
| Success metrics | Automated verification commands |
### JSON-Based PRD (Matt Pocock Method)
For scoping work correctly and preventing context rot:
```json
{
"project": "MyApp",
"features": [
{
"id": "auth",
"description": "JWT authentication system",
"priority": 1,
"passes": false,
"acceptance": "npm run test:auth passes"
},
{
"id": "api",
"description": "REST API endpoints",
"priority": 2,
"passes": false,
"acceptance": "all endpoints return 200 for valid requests"
}
]
}
```
Prompt the agent to:
1. Pick the highest priority feature with `passes: false`
2. Work ONLY on that feature
3. Update the passing status when acceptance criteria met
4. Commit progress to `progress.txt`
---
## Part 3: Directory Setup
### Initial Structure
```bash
mkdir my-project && cd my-project
git init
# Core prompt file
cat > PROMPT.md << 'EOF'
[Your structured PRD here]
EOF
# Progress tracker (critical for context persistence)
touch progress.txt
# Agent context files (optional but recommended)
mkdir -p agent_docs
touch agent_docs/tech_stack.md
touch agent_docs/code_patterns.md
touch agent_docs/testing.md
# Initial commit
git add .
git commit -m "Initial prompt and structure"
```
### Recommended Full Structure
```
my-project/
├── PROMPT.md # Main task definition
├── progress.txt # Append-only progress log
├── prd.json # JSON PRD for feature tracking
├── agent_docs/
│ ├── tech_stack.md # Tech decisions and rationale
│ ├── code_patterns.md # Project conventions
│ ├── testing.md # Test strategy
│ └── resources.md # External references
├── CLAUDE.md # Claude Code specific config
├── .cursorrules # Cursor config (if using)
├── .gitignore
├── README.md
└── src/
```
---
## Part 4: Execution Methods
### Method A: Official Ralph Wiggum Plugin (Recommended)
```bash
# Install from official plugin marketplace
/plugin marketplace add anthropics/claude-code
/plugin install ralph-wiggum@claude-plugins-official
# Basic usage
/ralph-wiggum:ralph-loop "<prompt>" --max-iterations N
# With completion promise
/ralph-wiggum:ralph-loop "<prompt>" --max-iterations N --completion-promise "text"
# Cancel active loop
/ralph-wiggum:cancel-ralph
```
**Example:**
```bash
/ralph-wiggum:ralph-loop "Build the authentication system as specified in PROMPT.md. Output <promise>AUTH_COMPLETE</promise> when all auth tests pass." --max-iterations 30 --completion-promise "AUTH_COMPLETE"
```
### Method B: Raw Bash Loop (Universal)
```bash
#!/bin/bash
# ralph-loop.sh
MAX_ITERATIONS=${1:-30}
ITERATION=0
while [ $ITERATION -lt $MAX_ITERATIONS ]; do
echo "=== Iteration $((ITERATION + 1)) of $MAX_ITERATIONS ==="
# Feed prompt to Claude Code
cat PROMPT.md | claude --print
# Check for completion promise
if grep -rq "<promise>PROJECT_COMPLETE</promise>" . 2>/dev/null; then
echo "Project complete at iteration $((ITERATION + 1))"
exit 0
fi
# Check for abort
if grep -rq "<promise>ABORT_BLOCKED</promise>" . 2>/dev/null; then
echo "Agent blocked. Check logs."
exit 1
fi
# Auto-commit progress
git add -A
git diff --cached --quiet || git commit -m "Ralph iteration $((ITERATION + 1))"
ITERATION=$((ITERATION + 1))
done
echo "Max iterations reached"
```
### Method C: Enhanced Loop with Safety Controls
```bash
#!/bin/bash
set -e
MAX_ITERATIONS=${1:-30}
FAIL_COUNT=0
MAX_CONSECUTIVE_FAILS=5
for i in $(seq 1 $MAX_ITERATIONS); do
echo "=== Iteration $i of $MAX_ITERATIONS ==="
echo "Started: $(date)" >> progress.txt
# Run Claude with timeout (10 minutes per iteration)
timeout 600 bash -c 'cat PROMPT.md | claude --print' || {
echo "Iteration timed out, continuing..."
echo "Iteration $i: TIMEOUT" >> progress.txt
}
# Commit whatever got done
git add -A
git diff --cached --quiet || git commit -m "Ralph iteration $i"
# Check completion
if grep -rq "<promise>PROJECT_COMPLETE</promise>" .; then
echo "Complete at iteration $i"
echo "PROJECT COMPLETE at iteration $i" >> progress.txt
exit 0
fi
# Check abort
if grep -rq "<promise>ABORT_BLOCKED</promise>" .; then
echo "Agent signaled abort"
exit 1
fi
# Verify tests pass (prevents compounding errors)
if command -v npm &> /dev/null && [ -f package.json ]; then
if ! npm test 2>/dev/null; then
FAIL_COUNT=$((FAIL_COUNT + 1))
echo "Test failure #$FAIL_COUNT" >> progress.txt
if [ $FAIL_COUNT -gt $MAX_CONSECUTIVE_FAILS ]; then
echo "Too many consecutive test failures. Stopping."
exit 1
fi
else
FAIL_COUNT=0
fi
fi
echo "Iteration $i complete" >> progress.txt
done
echo "Max iterations reached without completion"
```
### Method D: Amp/Sourcegraph Loop
```bash
while :; do cat PROMPT.md | npx --yes @sourcegraph/amp ; done
```
---
## Part 5: Prompt Engineering for Ralph
### Critical Prompt Elements
1. **Clear Completion Signal**
```markdown
Output <promise>COMPLETE</promise> when:
- All tests pass
- Linting passes
- Build succeeds
```
2. **Atomic Task Scoping**
```markdown
Work ONLY on the highest-priority incomplete feature.
Do NOT proceed to next feature until current feature passes all acceptance criteria.
```
3. **Progress Tracking**
```markdown
After each significant change:
1. Commit your work with descriptive message
2. Append progress to progress.txt (use verb 'append', do not modify previous entries)
3. Run tests to verify state
```
4. **CI Green Requirement**
```markdown
Each commit MUST pass all tests and type checks.
Never commit code that breaks the build.
Run `npm run build && npm run test && npm run lint` before every commit.
```
5. **Self-Correction Pattern**
```markdown
If tests fail:
1. Read the error message
2. Identify root cause
3. Implement fix
4. Run tests again
5. Repeat until green
```
### Prompt Tuning Process
Geoffrey Huntley's guitar tuning metaphor:
1. **Start with no guardrails**: Let Ralph build the playground first
2. **Add signs when Ralph fails**: When Ralph falls off the slide, add a sign saying "SLIDE DOWN, DON'T JUMP"
3. **Iterate on failures**: Each failure teaches you what guardrails to add
4. **Eventually get a new Ralph**: Once prompts are tuned, the defects disappear
### Example: Feature Implementation Prompt
```markdown
# Task: Implement User Authentication
Read PROMPT.md for full project context.
## Current Feature
Implement JWT-based user authentication.
## Requirements
- POST /auth/register - Create new user
- POST /auth/login - Return JWT token
- GET /auth/me - Return current user (protected)
- Password hashing with bcrypt
- Token expiration: 24 hours
## Process
1. Write failing tests first (TDD)
2. Implement minimal code to pass
3. Run tests
4. If failing, debug and fix
5. Refactor if needed
6. Repeat until all green
## Success Criteria
- All tests in tests/auth.test.ts pass
- No linter errors
- Coverage > 80% for auth module
## On Completion
1. Update prd.json: set auth.passes = true
2. Append summary to progress.txt
3. Output <promise>AUTH_DONE</promise>
## If Stuck After 10 Attempts
- Document blocking issues in progress.txt
- List attempted approaches
- Output <promise>AUTH_BLOCKED</promise>
```
---
## Part 6: AFK Ralph vs HOTL Ralph
### AFK (Away From Keyboard) Ralph
For overnight/weekend runs on well-defined tasks:
```markdown
## AFK Mode Instructions
You are running autonomously. Human will not intervene.
Rules:
1. Never stop to ask questions - make reasonable decisions
2. If blocked, try 3 alternative approaches before marking blocked
3. Commit frequently (every 5-10 minutes of work)
4. Log all decisions to progress.txt
5. Prefer reversible decisions over blocking
6. If uncertain, implement the simpler option
7. Document assumptions made
Safety:
- Never delete data without explicit instruction
- Never modify files outside project directory
- Never make network requests to production systems
- Stop if costs approach $100 in estimated tokens
```
### HOTL (Human On The Loop) Ralph
For complex tasks requiring occasional judgment:
```markdown
## HOTL Mode Instructions
Human is monitoring but not actively directing.
Rules:
1. Work autonomously on implementation details
2. Signal for human input on:
- Architectural decisions
- Security-critical code
- External API integrations
- Ambiguous requirements
3. Use <question>Your question here</question> tags when blocked
4. Continue with other work while waiting for response
5. Log questions to progress.txt with timestamp
```
---
## Part 7: Advanced Patterns
### Parallel Development with Git Worktrees
```bash
# Create isolated worktrees for parallel features
git worktree add ../project-auth -b feature/auth
git worktree add ../project-api -b feature/api
git worktree add ../project-ui -b feature/ui
# Terminal 1: Auth
cd ../project-auth
/ralph-wiggum:ralph-loop "Implement authentication..." --max-iterations 30
# Terminal 2: API (simultaneously)
cd ../project-api
/ralph-wiggum:ralph-loop "Build REST API..." --max-iterations 30
# Terminal 3: UI (simultaneously)
cd ../project-ui
/ralph-wiggum:ralph-loop "Build frontend components..." --max-iterations 30
# Later: merge completed features
git checkout main
git merge feature/auth
git merge feature/api
git merge feature/ui
```
### Multi-Phase Sequential Development
```bash
# Phase 1: Data layer
/ralph-wiggum:ralph-loop "Phase 1: Build data models and database schema. Output <promise>PHASE1_DONE</promise>" --max-iterations 20 --completion-promise "PHASE1_DONE"
# Phase 2: Business logic
/ralph-wiggum:ralph-loop "Phase 2: Build service layer and business logic. Output <promise>PHASE2_DONE</promise>" --max-iterations 25 --completion-promise "PHASE2_DONE"
# Phase 3: API
/ralph-wiggum:ralph-loop "Phase 3: Build API endpoints. Output <promise>PHASE3_DONE</promise>" --max-iterations 25 --completion-promise "PHASE3_DONE"
# Phase 4: Frontend
/ralph-wiggum:ralph-loop "Phase 4: Build UI. Output <promise>PHASE4_DONE</promise>" --max-iterations 30 --completion-promise "PHASE4_DONE"
```
### Overnight Batch Processing
```bash
#!/bin/bash
# overnight-work.sh
LOG_FILE="overnight-$(date +%Y%m%d).log"
echo "Starting overnight batch: $(date)" >> $LOG_FILE
# Project 1
cd /path/to/project1
echo "Starting project1..." >> $LOG_FILE
timeout 14400 bash -c '/ralph-wiggum:ralph-loop "$(cat PROMPT.md)" --max-iterations 50' >> $LOG_FILE 2>&1
echo "Project1 finished: $(date)" >> $LOG_FILE
# Project 2
cd /path/to/project2
echo "Starting project2..." >> $LOG_FILE
timeout 14400 bash -c '/ralph-wiggum:ralph-loop "$(cat PROMPT.md)" --max-iterations 50' >> $LOG_FILE 2>&1
echo "Project2 finished: $(date)" >> $LOG_FILE
echo "Batch complete: $(date)" >> $LOG_FILE
# Optional: send notification
# curl -X POST "https://hooks.slack.com/..." -d '{"text":"Overnight batch complete"}'
```
---
## Part 8: Quality Control and Safety
### Feedback Loops (Critical)
1. **Tests**: Every commit must pass all tests
2. **Types**: Full type checking on every commit
3. **Lint**: Consistent style enforcement
4. **Build**: Verify deployability continuously
```markdown
## Mandatory Verification Sequence
Before EVERY commit, run:
```bash
npm run typecheck && npm run lint && npm run test && npm run build
```
If ANY command fails:
1. Do NOT commit
2. Fix the issue
3. Re-run verification
4. Only commit when all pass
```
### Cost Control
| Context Size | Approx Cost/Hour | Recommended Max Iterations |
|-------------|------------------|---------------------------|
| Small (<50k tokens) | $15-25 | 50 |
| Medium (50-200k tokens) | $25-50 | 30 |
| Large (>200k tokens) | $50-100+ | 20 |
```bash
# Set hard limits
/ralph-wiggum:ralph-loop "..." --max-iterations 30
# Monitor during execution
# Check ~/.claude/usage.log or equivalent
```
### Safety Guardrails
```markdown
## Safety Rules
NEVER:
- Delete production data
- Modify files outside project directory
- Execute commands with sudo
- Make requests to production APIs
- Store credentials in code
- Commit sensitive data to git
ALWAYS:
- Use environment variables for secrets
- Mock external services in tests
- Operate in sandboxed environment
- Maintain ability to rollback via git
```
### Recovery Procedures
```bash
# If Ralph goes off the rails
/ralph-wiggum:cancel-ralph
# Review what happened
git log --oneline -20
git diff HEAD~5
# Rollback if needed
git reset --hard HEAD~N
# Clean up any mess
git clean -fd
# Restart with adjusted prompt
```
---
## Part 9: When to Use (and Not Use) Ralph
### Good For
- **Greenfield projects** with clear specifications
- **Mechanical tasks**: migrations, refactors, test coverage
- **Well-defined tasks** with automatic verification
- **Batch operations**: lint fixes, dependency updates
- **Documentation** generation
- **Test writing** with clear acceptance criteria
- **Overnight development** while you sleep
### Not Good For
- **Ambiguous requirements** without binary success criteria
- **Architectural decisions** requiring human judgment
- **Security-critical code** needing human review
- **Exploratory work** without clear goals
- **Production debugging** requiring context
- **UX/design decisions** requiring human taste
- **Complex integrations** with undocumented APIs
### Decision Matrix
| Task Type | Ralph Suitability | Recommended Approach |
|-----------|------------------|---------------------|
| New API endpoint | High | AFK Ralph |
| Database migration | High | AFK Ralph |
| Test coverage | High | AFK Ralph |
| Security audit | Low | Manual review |
| UI polish | Medium | HOTL Ralph |
| Performance tuning | Medium | HOTL Ralph |
| Architecture design | Low | Manual design + Ralph implementation |
| Bug investigation | Low | Manual + targeted Ralph |
---
## Part 10: Real-World Results
### Documented Successes
- **CURSED Programming Language**: 3-month continuous loop, built complete esoteric language
- **YC Hackathon**: 6 repositories shipped overnight for $297 in API costs
- **$50k Contract**: Delivered complete MVP with Ralph for ~$300 in compute
- **Integration Test Optimization**: Reduced runtime from 4 minutes to 2 seconds
### Cost Expectations
| Project Complexity | Estimated Cost | Typical Iterations |
|-------------------|----------------|-------------------|
| Simple CRUD app | $50-100 | 20-30 |
| Medium SaaS MVP | $200-500 | 50-100 |
| Complex system | $500-2000+ | 100-300 |
---
## Part 11: Quick Reference
### Checklist: Before Starting Ralph
- [ ] Git initialized
- [ ] PROMPT.md created with binary completion criteria
- [ ] progress.txt created (empty)
- [ ] Test framework configured
- [ ] Linting configured
- [ ] Build command working
- [ ] --max-iterations set appropriately
- [ ] Cost limits understood
- [ ] Rollback strategy clear
### Checklist: During Ralph Run
- [ ] Monitoring progress.txt
- [ ] Watching git log
- [ ] Checking test results
- [ ] Monitoring token usage
- [ ] Ready to /cancel-ralph if needed
### Checklist: After Ralph Run
- [ ] Review all commits
- [ ] Run full test suite
- [ ] Review code quality
- [ ] Squash/rebase commits if desired
- [ ] Document any issues found
- [ ] Update PRD with lessons learned
### Command Reference
```bash
# Start loop
/ralph-wiggum:ralph-loop "<prompt>" --max-iterations N --completion-promise "TEXT"
# Cancel loop
/ralph-wiggum:cancel-ralph
# Help
/ralph-wiggum:help
# Raw bash alternative
while :; do cat PROMPT.md | claude --print ; done
```
---
## Appendix A: Complete PROMPT.md Template
```markdown
# Project: [NAME]
## Context
[2-3 sentences about what this project is]
## Tech Stack
- Runtime: Node.js 20 / Python 3.12 / Go 1.22
- Framework: Express / FastAPI / Gin
- Database: PostgreSQL 16
- ORM: Prisma / SQLAlchemy / GORM
- Testing: Jest / pytest / go test
- Linting: ESLint / ruff / golangci-lint
## Directory Structure
```
src/
├── controllers/ # HTTP handlers
├── services/ # Business logic
├── models/ # Data models
├── middleware/ # Auth, logging, etc.
├── utils/ # Helpers
└── types/ # Type definitions
tests/
├── unit/
├── integration/
└── e2e/
```
## Completion Criteria
All must be true:
1. `npm run build` exits 0
2. `npm run test` exits 0 with >80% coverage
3. `npm run lint` exits 0
4. README.md contains API documentation
5. All features in prd.json have passes=true
Output `<promise>PROJECT_COMPLETE</promise>` when ALL criteria met.
## Features
### Phase 1: Foundation (Priority 1)
- [ ] Project setup with all dependencies
- [ ] Database connection and migrations
- [ ] Basic health check endpoint
- [ ] Logging middleware
- [ ] Error handling middleware
### Phase 2: Core (Priority 2)
- [ ] User model and CRUD
- [ ] Authentication (JWT)
- [ ] Authorization middleware
- [ ] [Feature specific to project]
- [ ] [Feature specific to project]
### Phase 3: Integration (Priority 3)
- [ ] [External service]
- [ ] Email notifications
- [ ] File uploads
### Phase 4: Polish (Priority 4)
- [ ] API documentation
- [ ] Rate limiting
- [ ] Caching
- [ ] Performance optimization
## Constraints
- All async operations must have error handling
- No hardcoded credentials
- All endpoints must validate input
- All database operations must use transactions where appropriate
- Test coverage minimum 80%
- No TypeScript `any` types / Python type hints required
## Working Process
1. Read this file and prd.json
2. Select highest priority feature with passes=false
3. Write failing tests first
4. Implement minimal code to pass
5. Verify: `npm run build && npm run test && npm run lint`
6. If fail: fix and retry
7. If pass: commit with descriptive message
8. Append progress to progress.txt
9. Update prd.json feature.passes = true
10. Repeat until all features complete
## Abort Conditions
Output `<promise>ABORT_BLOCKED</promise>` if:
- Circular dependency cannot be resolved after 5 attempts
- External API required but unavailable
- Fundamental architecture change needed
- After 15 iterations on same feature without progress
Document blocking issue in progress.txt before aborting.
## Safety
- Never modify files outside project directory
- Never use sudo
- Never store real credentials
- Always use .env for configuration
- Commit frequently
```
---
## Appendix B: Troubleshooting
### "Claude keeps stopping early"
**Cause**: Completion promise detected incorrectly or unclear criteria
**Fix**: Make completion criteria more specific, use unique promise text
### "Tests keep failing in loop"
**Cause**: Breaking changes accumulating
**Fix**: Add stronger "CI green" requirement, reduce iteration count, add checkpoint validation
### "Context getting too large"
**Cause**: Too much history accumulating
**Fix**: Use phases with fresh context each, summarize progress.txt periodically
### "Ralph taking wrong direction"
**Cause**: Ambiguous requirements
**Fix**: Add explicit constraints, use the "sign next to slide" pattern - add guardrails for specific failure modes
### "Loop running forever"
**Cause**: Impossible completion criteria
**Fix**: Always set --max-iterations, add abort conditions, monitor manually
### "Costs spiraling"
**Cause**: Large context, too many iterations
**Fix**: Break into smaller phases, set strict iteration limits, use smaller models for simpler tasks
---
*Framework version: 1.0*
*Last updated: January 2026*
*Based on techniques by Geoffrey Huntley, Matt Pocock, and the Claude Code community*

961
docs/guide.md Normal file
View File

@@ -0,0 +1,961 @@
# Ralph Method: Step-by-Step Implementation Guide
## From Idea to Deployed App Using 100% Vibe Coding
This guide walks you through the exact steps to go from "I have an app idea" to "Claude Code built it for me overnight."
---
## Overview: The 7 Stages
| Stage | What You Do | Output |
|-------|-------------|--------|
| 1 | Dump your idea | Raw idea document |
| 2 | Expand into full spec | Structured requirements |
| 3 | Convert to machine PRD | PROMPT.md + prd.json |
| 4 | Set up project scaffold | Ready-to-run directory |
| 5 | Execute Phase 1 (Foundation) | Working skeleton |
| 6 | Execute remaining phases | Complete application |
| 7 | Review and polish | Production-ready code |
**Total human effort**: 1-3 hours of prompting and setup
**Total Ralph effort**: Hours to days of autonomous coding
---
## Stage 1: Idea Dump (15-30 minutes)
### Step 1.1: Brain Dump
Open any text editor or chat with Claude/ChatGPT. Write everything in your head about the app. Don't organize, just dump.
**Prompt to use:**
```
I have an app idea. I'm going to brain dump everything about it.
Don't respond until I say "DONE". Just acknowledge each message.
[Then type everything: features, users, problems it solves, tech preferences,
things you've seen in other apps you like, random thoughts, everything]
DONE
```
### Step 1.2: Initial Structuring
After your dump, use this prompt:
```
Now organize what I described into these categories:
1. PROBLEM: What problem does this solve? Who has this problem?
2. SOLUTION: What is the app and how does it solve the problem?
3. USERS: Who are the primary users? What are their goals?
4. CORE FEATURES: What are the absolute must-have features for v1?
5. NICE-TO-HAVE: What features can wait for v2?
6. TECH PREFERENCES: Any specific technologies I mentioned or prefer?
7. CONSTRAINTS: Any limitations, requirements, or non-negotiables?
8. SIMILAR APPS: What existing apps is this similar to?
Output as a structured document I can save.
```
### Step 1.3: Save Output
Save the response as `docs/idea-dump.md` in a new folder for your project.
**Checkpoint**: You should have a rough but organized document describing your app.
---
## Stage 2: Expand to Full Specification (30-60 minutes)
### Step 2.1: Architecture Classification
First, let the LLM identify what type of application this is:
```
Based on my app idea, classify this project:
1. APPLICATION TYPE: What kind of application is this?
- Web application (frontend + backend)
- Web frontend only (static/SPA)
- Backend API only
- Desktop application (Electron, Tauri, native)
- CLI tool
- Mobile app (native, React Native, Flutter)
- Library/package
- Script/automation
- Game
- Other (specify)
2. INTERFACE TYPES NEEDED: Based on the app type, what interfaces are relevant?
- REST API (web backends, mobile backends)
- GraphQL API (complex data relationships)
- IPC channels (desktop apps with multi-process)
- Module interfaces (libraries, internal boundaries)
- CLI arguments/flags (command-line tools)
- File formats (apps that save/load data)
- WebSocket/real-time (chat, live updates)
- System integrations (OS APIs, hardware, file system)
- Plugin architecture (extensible apps)
- None/minimal (simple scripts)
3. DATA PERSISTENCE: How will data be stored?
- Remote database (PostgreSQL, MySQL, MongoDB)
- Local database (SQLite, LevelDB)
- File-based (JSON, YAML, custom format)
- In-memory only
- Cloud storage (S3, etc.)
- No persistence needed
4. DEPLOYMENT MODEL:
- Cloud hosted (Vercel, AWS, GCP, etc.)
- Self-hosted server
- Desktop installer (Windows, macOS, Linux)
- Package registry (npm, PyPI, crates.io)
- App store (mobile)
- No deployment (local script)
Output your classification with brief justification for each choice.
```
### Step 2.2: Feature Decomposition
Take your structured idea and expand each feature:
```
For each CORE FEATURE in my idea document, break it down into:
1. User Story: "As a [user], I want to [action] so that [benefit]"
2. Acceptance Criteria: Specific, testable conditions that prove it works
3. Data Required: What data/models does this feature need?
4. Interface Points: Based on the app type identified, what interfaces does this feature need?
- For web apps: API endpoints
- For desktop apps: IPC handlers or module functions
- For CLI tools: commands/subcommands and flags
- For libraries: public API functions/classes
5. UI/UX Components: What user-facing elements are needed (if applicable)?
Be specific and concrete. Each acceptance criterion must be binary (pass/fail).
```
### Step 2.3: Technical Decisions
Get explicit about the tech stack:
```
Based on my app requirements and the architecture classification, recommend a tech stack.
Consider:
- Application type: [from Step 2.1]
- My preferences: [your preferences, e.g., "TypeScript", "Python", "whatever is fastest", or "none"]
- Deployment target: [from Step 2.1, or your preference]
- Data persistence: [from Step 2.1]
For each technology choice, provide:
1. The specific technology/framework
2. Why it fits this project and architecture
3. The exact versions to use (current stable)
4. Any critical dependencies or companion tools
Also identify:
- Build tools needed
- Testing framework appropriate for this app type
- Linting/formatting tools
- CI/CD approach (if applicable)
Output as a tech-stack.md file.
```
### Step 2.4: Data Model Design
```
Based on the features and persistence model identified, design the data structures:
For each model/entity:
1. Name
2. Fields with types
3. Relationships to other models
4. Validation rules
5. Example data
Adapt the format to the persistence type:
- For databases: include indexes, constraints, migrations approach
- For file-based: include file format specification, versioning strategy
- For in-memory: include initialization and state management approach
Output as a data specification.
```
### Step 2.5: Interface Contract
```
Based on the interface types identified in Step 2.1, design the contracts:
FOR REST/GraphQL APIs:
- Method and path (e.g., POST /api/users)
- Request/response schemas
- Authentication requirements
- Error responses
FOR DESKTOP IPC:
- Channel names
- Message types and payloads
- Direction (main→renderer, renderer→main, bidirectional)
FOR CLI TOOLS:
- Commands and subcommands
- Flags and arguments with types
- Input/output formats
- Exit codes
FOR LIBRARIES:
- Public functions/classes/types
- Parameters and return types
- Error handling approach
- Usage examples
FOR FILE FORMATS:
- Schema/structure specification
- Versioning approach
- Migration between versions
Design only the interface types relevant to this application.
Group by feature area. Output as an interface specification.
```
### Step 2.6: Save Everything
You should now have:
- `docs/idea-dump.md` (from Stage 1)
- `docs/architecture.md` (app type, interfaces, persistence, deployment)
- `docs/features.md` (feature breakdown with acceptance criteria)
- `docs/tech-stack.md` (technologies with versions)
- `docs/data-models.md` (data structures)
- `docs/interfaces.md` (API/IPC/CLI/library contracts as applicable)
**Checkpoint**: You have a complete human-readable specification tailored to your app type.
---
## Stage 3: Convert to Machine PRD (30-45 minutes)
### Step 3.1: Create PROMPT.md
This is the master file Ralph will read. Use this prompt:
```
Convert my specification documents into a PROMPT.md file for an AI coding agent.
Context from my architecture classification:
- Application type: [from Step 2.1]
- Interface types: [from Step 2.1]
- Persistence model: [from Step 2.1]
- Deployment model: [from Step 2.1]
Requirements for the PROMPT.md:
1. Single file that contains everything the agent needs
2. Tailored to the specific application type (not generic web app assumptions)
3. Clear completion criteria with exact commands to verify
4. Phased approach appropriate to this app type:
- Web apps: Foundation → Core → Integration → Polish
- Desktop apps: Foundation → Core UI → System Integration → Packaging
- CLI tools: Foundation → Commands → I/O Handling → Distribution
- Libraries: Foundation → Core API → Documentation → Publishing
- Adapt as needed for other types
5. Binary pass/fail acceptance criteria for every feature
6. Interface specifications appropriate to the app type
7. Explicit constraints and safety rules
8. Promise tags for completion signals
Use this structure:
# Project: [Name]
## Objective
[One sentence]
## Application Type
[Classification from Step 2.1]
## Tech Stack
[Exact versions]
## Completion Criteria
[Numbered list of verification commands appropriate to this app type]
## Phase 1: Foundation
[Setup tasks with acceptance criteria]
## Phase 2: Core [Features/UI/Commands/API - varies by app type]
[Each feature with binary acceptance]
## Phase 3: [Integration/System/I/O - varies by app type]
[External services, system integration, etc.]
## Phase 4: [Polish/Packaging/Publishing - varies by app type]
[Docs, distribution, optimization]
## Constraints
[Hard rules]
## Abort Conditions
[When to stop and signal]
## Working Process
[Step-by-step instructions for each iteration]
Include the promise tags:
- <promise>PROJECT_COMPLETE</promise> for full completion
- <promise>PHASE_N_COMPLETE</promise> for phase completion
- <promise>ABORT_BLOCKED</promise> for blocking issues
Here are my spec documents:
[Paste all your docs including architecture.md]
```
### Step 3.2: Create prd.json
For granular progress tracking:
```
Create a prd.json file that tracks each feature as a separate item.
Format:
{
"project": "MyApp",
"features": [
{
"id": "unique-id",
"phase": 1,
"name": "Feature Name",
"description": "What it does",
"priority": 1,
"passes": false,
"acceptance": "Exact command or condition that proves completion",
"dependencies": ["other-feature-ids"]
}
]
}
Order by phase, then by priority within phase.
Include all features from my specification.
Set all "passes" to false initially.
```
### Step 3.3: Create progress.txt Template
Create an empty file with header:
```
# Progress Log
# Format: [TIMESTAMP] [ITERATION] [STATUS] - [DETAILS]
# Agent: Append only, never modify previous entries
---
```
### Step 3.4: Validate Your PRD
Final check prompt:
```
Review this PROMPT.md for an AI coding agent. Check for:
1. AMBIGUITY: Any requirements that aren't binary pass/fail?
2. MISSING COMMANDS: Every verification must have an exact command
3. DEPENDENCIES: Are phases ordered correctly?
4. COMPLETENESS: Can an agent build this without asking questions?
5. SAFETY: Are there guardrails against destructive actions?
List any issues found and suggest fixes.
[Paste your PROMPT.md]
```
Fix any issues identified.
**Checkpoint**: You have `PROMPT.md`, `prd.json`, and `progress.txt` ready.
---
## Stage 4: Project Scaffold Setup (15-30 minutes)
### Step 4.1: Create Directory Structure
Run these commands:
```bash
# Create project directory
mkdir my-app && cd my-app
# Initialize git (CRITICAL - Ralph uses git for memory)
git init
# Create core Ralph files
touch PROMPT.md
touch prd.json
touch progress.txt
# Create documentation directory
mkdir -p docs
# Create agent context directory (optional but recommended)
mkdir -p agent_docs
touch agent_docs/tech_stack.md
touch agent_docs/code_patterns.md
touch agent_docs/testing.md
# Create Claude Code config (optional)
touch CLAUDE.md
```
### Step 4.2: Populate Files
Copy your generated content:
- Paste PROMPT.md content
- Paste prd.json content
- Paste progress.txt template
- Copy spec docs to `docs/`
### Step 4.3: Create .gitignore
```bash
cat > .gitignore << 'EOF'
node_modules/
.env
.env.local
*.log
dist/
build/
coverage/
.DS_Store
__pycache__/
*.pyc
.venv/
EOF
```
### Step 4.4: Create CLAUDE.md (Optional but Recommended)
This file gives Claude Code persistent instructions:
```bash
cat > CLAUDE.md << 'EOF'
# Claude Code Instructions
## Project Context
Read PROMPT.md for full requirements.
Read prd.json for feature tracking.
Append progress to progress.txt after each significant change.
## Working Rules
1. Always run tests before committing
2. Never commit failing code
3. Update prd.json when features complete
4. Use conventional commit messages
5. Ask no questions - make reasonable decisions
## Commands
- Build: npm run build
- Test: npm run test
- Lint: npm run lint
- All: npm run build && npm run test && npm run lint
EOF
```
### Step 4.5: Initial Commit
```bash
git add .
git commit -m "Initial project setup with Ralph configuration"
```
**Checkpoint**: Your project directory is ready for Ralph.
---
## Stage 5: Execute Phase 1 - Foundation (1-3 hours automated)
### Step 5.1: Install Ralph Plugin
In Claude Code:
```
/plugin marketplace add anthropics/claude-code
/plugin install ralph-wiggum@claude-plugins-official
```
### Step 5.2: Start Phase 1 Loop
```
/ralph-wiggum:ralph-loop "Execute Phase 1 (Foundation) from PROMPT.md.
Read PROMPT.md for full context.
Read prd.json for feature tracking.
Work on Phase 1 items only. For each item:
1. Write tests first
2. Implement the feature
3. Verify tests pass
4. Update prd.json (set passes=true)
5. Commit with descriptive message
6. Append progress to progress.txt
Run verification after each feature:
npm run build && npm run test && npm run lint
When ALL Phase 1 features in prd.json have passes=true:
Output <promise>PHASE_1_COMPLETE</promise>
If blocked after 10 attempts on same feature:
Document in progress.txt and output <promise>PHASE_1_BLOCKED</promise>" --max-iterations 30 --completion-promise "PHASE_1_COMPLETE"
```
### Step 5.3: Monitor (Optional)
While Ralph runs, you can monitor:
```bash
# Watch progress
tail -f progress.txt
# Watch git commits
watch -n 10 'git log --oneline -10'
# Check test status
watch -n 30 'npm test 2>&1 | tail -20'
```
### Step 5.4: Handle Completion
**If PHASE_1_COMPLETE:**
```bash
# Review what was built
git log --oneline
npm run test
npm run build
# Continue to Phase 2
```
**If PHASE_1_BLOCKED:**
```bash
# Check what blocked
cat progress.txt | tail -50
# Review the issue
# Manually fix or adjust PROMPT.md
# Restart Phase 1 with updated prompt
```
**Checkpoint**: Foundation is complete. You have a working project skeleton.
---
## Stage 6: Execute Remaining Phases (2-8 hours automated per phase)
### Step 6.1: Phase 2 - Core Features
```
/ralph-wiggum:ralph-loop "Execute Phase 2 (Core Features) from PROMPT.md.
Phase 1 is complete. Now implement Phase 2 features.
Read PROMPT.md for requirements.
Read prd.json for feature list and status.
For each Phase 2 feature:
1. Check dependencies are met (Phase 1 complete)
2. Write comprehensive tests
3. Implement feature
4. Verify all tests pass
5. Update prd.json
6. Commit
7. Log to progress.txt
Verification command:
npm run build && npm run test && npm run lint
When ALL Phase 2 features pass:
Output <promise>PHASE_2_COMPLETE</promise>
If blocked: <promise>PHASE_2_BLOCKED</promise>" --max-iterations 50 --completion-promise "PHASE_2_COMPLETE"
```
### Step 6.2: Phase 3 - Integration
```
/ralph-wiggum:ralph-loop "Execute Phase 3 (Integration) from PROMPT.md.
Phases 1-2 complete. Now implement Phase 3.
Focus on:
- External service integrations
- Authentication/Authorization
- Error handling
- Logging
For external services, use mocks in tests.
Document any API keys needed in .env.example.
When ALL Phase 3 features pass:
Output <promise>PHASE_3_COMPLETE</promise>" --max-iterations 40 --completion-promise "PHASE_3_COMPLETE"
```
### Step 6.3: Phase 4 - Polish
```
/ralph-wiggum:ralph-loop "Execute Phase 4 (Polish) from PROMPT.md.
Phases 1-3 complete. Final polish.
Tasks:
- Complete README.md with setup instructions
- Add API documentation
- Handle edge cases
- Add input validation
- Improve error messages
- Add any missing tests (target >80% coverage)
When done and all PROMPT.md completion criteria met:
Output <promise>PROJECT_COMPLETE</promise>" --max-iterations 30 --completion-promise "PROJECT_COMPLETE"
```
### Step 6.4: Overnight Batch (Alternative)
If you want all phases to run overnight:
```bash
#!/bin/bash
# run-all-phases.sh
echo "Starting full build: $(date)"
# Phase 1
claude -p '/ralph-wiggum:ralph-loop "Execute Phase 1..." --max-iterations 30 --completion-promise "PHASE_1_COMPLETE"'
# Phase 2
claude -p '/ralph-wiggum:ralph-loop "Execute Phase 2..." --max-iterations 50 --completion-promise "PHASE_2_COMPLETE"'
# Phase 3
claude -p '/ralph-wiggum:ralph-loop "Execute Phase 3..." --max-iterations 40 --completion-promise "PHASE_3_COMPLETE"'
# Phase 4
claude -p '/ralph-wiggum:ralph-loop "Execute Phase 4..." --max-iterations 30 --completion-promise "PROJECT_COMPLETE"'
echo "Build complete: $(date)"
```
Run before bed:
```bash
chmod +x run-all-phases.sh
nohup ./run-all-phases.sh > build.log 2>&1 &
```
**Checkpoint**: All phases complete. Full application built.
---
## Stage 7: Review and Polish (1-2 hours manual)
### Step 7.1: Full Verification
```bash
# Run all checks
npm run build
npm run test
npm run lint
# Check coverage
npm run test -- --coverage
# Start the app and test manually
npm run dev
```
### Step 7.2: Code Review
Review key files:
```bash
# See all files created
find . -name "*.ts" -o -name "*.js" -o -name "*.tsx" | head -50
# Review main entry point
cat src/index.ts # or equivalent
# Review a core feature
cat src/services/[main-service].ts
# Check test quality
cat tests/[main-test].test.ts
```
### Step 7.3: Git Cleanup
```bash
# See all Ralph commits
git log --oneline
# Optional: squash into logical commits
git rebase -i HEAD~[number]
# Or create a clean branch
git checkout -b release/v1
git merge --squash main
git commit -m "v1.0.0 - Initial release"
```
### Step 7.4: Documentation Check
Verify README.md contains:
- [ ] Project description
- [ ] Prerequisites
- [ ] Installation steps
- [ ] Environment setup (.env.example)
- [ ] Running locally
- [ ] Running tests
- [ ] API documentation (or link to it)
- [ ] Deployment instructions
### Step 7.5: Security Scan
```bash
# Check for secrets
git log -p | grep -i "password\|secret\|key\|token" | head -20
# Run security audit
npm audit # or equivalent for your stack
```
### Step 7.6: Final Fixes
If you find issues, you can run targeted Ralph loops:
```
/ralph-wiggum:ralph-loop "Fix the following issues:
1. [Issue 1]
2. [Issue 2]
Run tests after each fix. Commit when green.
Output <promise>FIXES_COMPLETE</promise> when done." --max-iterations 10 --completion-promise "FIXES_COMPLETE"
```
**Checkpoint**: Production-ready application.
---
## Quick Reference: Commands Cheat Sheet
### Setup
```bash
mkdir my-app && cd my-app
git init
touch PROMPT.md prd.json progress.txt
```
### Ralph Plugin
```
/plugin install ralph-wiggum@claude-plugins-official
/ralph-wiggum:ralph-loop "<prompt>" --max-iterations N --completion-promise "TEXT"
/ralph-wiggum:cancel-ralph
```
### Monitoring
```bash
tail -f progress.txt
watch -n 10 'git log --oneline -5'
```
### Recovery
```bash
/ralph-wiggum:cancel-ralph
git log --oneline -10
git reset --hard HEAD~N
```
---
## Quick Reference: Time Estimates
| Stage | Human Time | Ralph Time |
|-------|-----------|------------|
| 1. Idea Dump | 15-30 min | - |
| 2. Expand Spec | 30-60 min | - |
| 3. Convert to PRD | 30-45 min | - |
| 4. Setup Scaffold | 15-30 min | - |
| 5. Phase 1 | 5 min | 1-3 hours |
| 6. Phases 2-4 | 15 min | 3-12 hours |
| 7. Review | 1-2 hours | - |
| **Total Human** | **3-5 hours** | - |
| **Total Ralph** | - | **4-15 hours** |
---
## Quick Reference: Prompts Library
### Brain Dump Prompt
```
I have an app idea. I'm going to brain dump everything about it.
Don't respond until I say "DONE". Just acknowledge each message.
```
### Structuring Prompt
```
Organize what I described into: PROBLEM, SOLUTION, USERS, CORE FEATURES,
NICE-TO-HAVE, TECH PREFERENCES, CONSTRAINTS, SIMILAR APPS.
```
### Feature Breakdown Prompt
```
For each feature, provide: User Story, Acceptance Criteria, Data Required,
API Endpoints, UI Components. Make acceptance criteria binary pass/fail.
```
### Tech Stack Prompt
```
Recommend a tech stack with exact versions. Consider [preferences].
Justify each choice.
```
### PROMPT.md Generation Prompt
```
Convert my specification into a PROMPT.md for an AI coding agent with:
phased approach, binary acceptance criteria, promise tags, and safety rules.
```
### Phase Execution Prompt
```
Execute Phase N from PROMPT.md. Read prd.json for tracking.
Write tests first, implement, verify, update prd.json, commit, log progress.
Output <promise>PHASE_N_COMPLETE</promise> when done.
```
---
## Troubleshooting Quick Fixes
| Problem | Solution |
|---------|----------|
| Ralph stops early | Check completion promise text matches exactly |
| Tests keep failing | Add "never commit failing code" to prompt |
| Wrong direction | Add specific constraints to PROMPT.md |
| Context too large | Break into smaller phases |
| Costs too high | Reduce --max-iterations, use phases |
| Loop infinite | Always set --max-iterations |
---
## Example: Complete Workflow
**Idea**: "A todo app with user accounts and team sharing"
**Stage 1 Output** (5 minutes):
```
PROBLEM: People need to manage tasks, existing apps are too complex
SOLUTION: Simple todo app with team sharing
USERS: Individuals, small teams
CORE FEATURES: Create todos, mark complete, share lists, user accounts
NICE-TO-HAVE: Due dates, labels, mobile app
TECH: TypeScript, prefer simple
```
**Stage 2 Output** (20 minutes):
- Architecture classification:
- App type: Web application (frontend + backend)
- Interfaces: REST API, WebSocket (for real-time sync)
- Persistence: Remote database (PostgreSQL)
- Deployment: Cloud hosted (Vercel + Railway)
- 4 core features broken into 12 acceptance criteria
- Tech stack: Node.js, Express, PostgreSQL, Prisma, Jest, React, Vite
- 5 data models: User, Team, List, Todo, TeamMember
- 15 API endpoints specified
**Stage 3 Output** (15 minutes):
- PROMPT.md: 200 lines with all phases (web app structure)
- prd.json: 12 features with acceptance criteria
**Stage 4** (10 minutes):
- Directory created, files populated, initial commit
**Stage 5-6** (overnight):
- Phase 1: 45 minutes, 8 iterations
- Phase 2: 3 hours, 24 iterations
- Phase 3: 2 hours, 18 iterations
- Phase 4: 1 hour, 12 iterations
- Total cost: ~$85
**Stage 7** (1 hour):
- All tests pass
- 84% coverage
- 3 minor fixes needed
- README complete
- Ready to deploy
**Total human time**: ~2 hours
**Total elapsed time**: ~10 hours (mostly overnight)
**Total cost**: ~$90
---
## Example: Desktop App Workflow
**Idea**: "A markdown note-taking app with local storage and vim keybindings"
**Stage 1 Output** (5 minutes):
```
PROBLEM: Existing note apps are bloated or cloud-dependent
SOLUTION: Fast local markdown editor with vim motions
USERS: Developers, writers who know vim
CORE FEATURES: Create/edit notes, vim keybindings, local file storage, search
NICE-TO-HAVE: Plugins, sync, mobile companion
TECH: Prefer Rust or TypeScript, must be fast
```
**Stage 2 Output** (25 minutes):
- Architecture classification:
- App type: Desktop application (Tauri)
- Interfaces: IPC channels (Rust backend ↔ React frontend), File formats (markdown + metadata JSON)
- Persistence: File-based (markdown files in user directory)
- Deployment: Desktop installer (Windows, macOS, Linux)
- 4 core features broken into 10 acceptance criteria
- Tech stack: Tauri 2.0, Rust, React, TypeScript, CodeMirror 6, Vitest
- 3 data structures: Note (file), NoteMetadata (index), AppConfig
- 8 IPC channels specified, file format documented
**Stage 3 Output** (15 minutes):
- PROMPT.md: 180 lines with desktop-appropriate phases:
- Phase 1: Foundation (Tauri setup, file system, config)
- Phase 2: Core UI (editor, vim bindings, note list)
- Phase 3: System Integration (file watching, search indexing)
- Phase 4: Packaging (installers, auto-update, icons)
- prd.json: 10 features tracked
**Stage 4** (10 minutes):
- Tauri project initialized, files populated, initial commit
**Stage 5-6** (overnight):
- Phase 1: 30 minutes, 6 iterations
- Phase 2: 4 hours, 32 iterations (vim bindings complex)
- Phase 3: 2 hours, 16 iterations
- Phase 4: 1.5 hours, 14 iterations
- Total cost: ~$120
**Stage 7** (1.5 hours):
- All tests pass
- App launches on all 3 platforms
- Vim bindings verified manually
- Installers build successfully
**Total human time**: ~2.5 hours
**Total elapsed time**: ~11 hours
**Total cost**: ~$130
---
*Guide version: 1.0*
*Works with: Claude Code + Ralph Wiggum plugin*
*Last updated: January 2026*