Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

Ralph is an autonomous AI agent loop that runs AI coding tools (Amp or Claude Code) repeatedly until all PRD items are complete. Each iteration is a fresh instance with clean context.
Ralph is an autonomous AI agent loop that runs AI coding tools (Amp, Claude Code or Gemini CLI) repeatedly until all PRD items are complete. Each iteration is a fresh instance with clean context.

## Commands

Expand All @@ -18,13 +18,17 @@ cd flowchart && npm run build

# Run Ralph with Claude Code
./ralph.sh --tool claude [max_iterations]

# Run Ralph with Gemini CLI
./ralph.sh --tool gemini [max_iterations]
```

## Key Files

- `ralph.sh` - The bash loop that spawns fresh AI instances (supports `--tool amp` or `--tool claude`)
- `ralph.sh` - The bash loop that spawns fresh AI instances (supports `--tool amp`, `--tool claude` or `--tool gemini`)
- `prompt.md` - Instructions given to each AMP instance
- `CLAUDE.md` - Instructions given to each Claude Code instance
- `CLAUDE.md` - Instructions given to each Claude Code instance
- `GEMINI.md` - Instructions given to each Gemini CLI instance
- `prd.json.example` - Example PRD format
- `flowchart/` - Interactive React Flow diagram explaining how Ralph works

Expand All @@ -41,7 +45,7 @@ npm run dev

## Patterns

- Each iteration spawns a fresh AI instance (Amp or Claude Code) with clean context
- Each iteration spawns a fresh AI instance (Amp, Claude Code or Gemini CLI) with clean context
- Memory persists via git history, `progress.txt`, and `prd.json`
- Stories should be small enough to complete in one context window
- Always update AGENTS.md with discovered patterns for future iterations
98 changes: 98 additions & 0 deletions GEMINI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Ralph Agent Instructions

You are an autonomous coding agent working on a software project.

## Your Task

1. Read the PRD at `prd.json` (in the same directory as this file)
2. Read the progress log at `progress.txt` (check Codebase Patterns section first)
3. Check you're on the correct branch from PRD `branchName`. If not, check it out or create from main.
4. Pick the **highest priority** user story where `passes: false`
5. Implement that single user story
6. Run quality checks (e.g., typecheck, lint, test - use whatever your project requires)
7. Update GEMINI.md files if you discover reusable patterns (see below)
8. If checks pass, commit ALL changes with message: `feat: [Story ID] - [Story Title]`
9. Update the PRD to set `passes: true` for the completed story
10. Append your progress to `progress.txt`

## Progress Report Format

APPEND to progress.txt (never replace, always append):
```
## [Date/Time] - [Story ID]
- What was implemented
- Files changed
- **Learnings for future iterations:**
- Patterns discovered (e.g., "this codebase uses X for Y")
- Gotchas encountered (e.g., "don't forget to update Z when changing W")
- Useful context (e.g., "the evaluation panel is in component X")
---
```

The learnings section is critical - it helps future iterations avoid repeating mistakes and understand the codebase better.

## Consolidate Patterns

If you discover a **reusable pattern** that future iterations should know, add it to the `## Codebase Patterns` section at the TOP of progress.txt (create it if it doesn't exist). This section should consolidate the most important learnings:

```
## Codebase Patterns
- Example: Use `sql<number>` template for aggregations
- Example: Always use `IF NOT EXISTS` for migrations
- Example: Export types from actions.ts for UI components
```

Only add patterns that are **general and reusable**, not story-specific details.

## Update GEMINI.md Files

Before committing, check if any edited files have learnings worth preserving in nearby GEMINI.md files:

1. **Identify directories with edited files** - Look at which directories you modified
2. **Check for existing GEMINI.md** - Look for GEMINI.md in those directories or parent directories
3. **Add valuable learnings** - If you discovered something future developers/agents should know:
- API patterns or conventions specific to that module
- Gotchas or non-obvious requirements
- Dependencies between files
- Testing approaches for that area
- Configuration or environment requirements

**Examples of good GEMINI.md additions:**
- "When modifying X, also update Y to keep them in sync"
- "This module uses pattern Z for all API calls"
- "Tests require the dev server running on PORT 3000"
- "Field names must match the template exactly"

**Do NOT add:**
- Story-specific implementation details
- Temporary debugging notes
- Information already in progress.txt

Only update GEMINI.md if you have **genuinely reusable knowledge** that would help future work in that directory.

## Quality Requirements

- ALL commits must pass your project's quality checks (typecheck, lint, test)
- Do NOT commit broken code
- Keep changes focused and minimal
- Follow existing code patterns

## Verification (Required for Frontend Stories)

For any story that changes UI, you MUST verify it works as expected. Use available tools to check the rendered output or run visual tests if configured.

## Stop Condition

After completing a user story, check if ALL stories have `passes: true`.

If ALL stories are complete and passing, reply with:
<promise>COMPLETE</promise>

If there are still stories with `passes: false`, end your response normally (another iteration will pick up the next story).

## Important

- Work on ONE story per iteration
- Commit frequently
- Keep CI green
- Read the Codebase Patterns section in progress.txt before starting
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Based on [Geoffrey Huntley's Ralph pattern](https://ghuntley.com/ralph/).
- One of the following AI coding tools installed and authenticated:
- [Amp CLI](https://ampcode.com) (default)
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) (`npm install -g @anthropic-ai/claude-code`)
- [Gemini CLI](https://gemini.google.com) (`npm install -g @google/gemini-cli`)
- `jq` installed (`brew install jq` on macOS)
- A git repository for your project

Expand All @@ -31,6 +32,8 @@ cp /path/to/ralph/ralph.sh scripts/ralph/
cp /path/to/ralph/prompt.md scripts/ralph/prompt.md # For Amp
# OR
cp /path/to/ralph/CLAUDE.md scripts/ralph/CLAUDE.md # For Claude Code
# OR
cp /path/to/ralph/GEMINI.md scripts/ralph/GEMINI.md # For Gemini CLI

chmod +x scripts/ralph/ralph.sh
```
Expand Down Expand Up @@ -117,7 +120,7 @@ This creates `prd.json` with user stories structured for autonomous execution.
./scripts/ralph/ralph.sh --tool claude [max_iterations]
```

Default is 10 iterations. Use `--tool amp` or `--tool claude` to select your AI coding tool.
Default is 10 iterations. Use `--tool amp`, `--tool claude` or `--tool gemini` to select your AI coding tool.

Ralph will:
1. Create a feature branch (from PRD `branchName`)
Expand Down Expand Up @@ -237,3 +240,4 @@ Ralph automatically archives previous runs when you start a new feature (differe
- [Geoffrey Huntley's Ralph article](https://ghuntley.com/ralph/)
- [Amp documentation](https://ampcode.com/manual)
- [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code)
(https://docs.anthropic.com/en/docs/claude-code)
9 changes: 6 additions & 3 deletions ralph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ while [[ $# -gt 0 ]]; do
done

# Validate tool choice
if [[ "$TOOL" != "amp" && "$TOOL" != "claude" ]]; then
echo "Error: Invalid tool '$TOOL'. Must be 'amp' or 'claude'."
if [[ "$TOOL" != "amp" && "$TOOL" != "claude" && "$TOOL" != "gemini" ]]; then
echo "Error: Invalid tool '$TOOL'. Must be 'amp', 'claude', or 'gemini'."
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand Down Expand Up @@ -90,9 +90,12 @@ for i in $(seq 1 $MAX_ITERATIONS); do
# 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
elif [[ "$TOOL" == "claude" ]]; then
# 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
else
# Gemini CLI: piping instructions file directly
OUTPUT=$(cat "$SCRIPT_DIR/GEMINI.md" | gemini --yolo 2>&1 | tee /dev/stderr) || true
fi

# Check for completion signal
Expand Down