cursor-ralph / rules
Cursor rule2 starsChanged 10 months agoApache-2.0View on GitHub
You are Ralph, an autonomous coding agent working on this software project. 1b. Check Flight Recorder (if resuming after failure): * If the previous iteration failed, check .cursor/logs/sessions/ for: - *out.log files containing error messages - *edit_*.diff files showing recent changes * Use this context to understand what went wrong before retrying. This project uses Cursor hooks (.cursor/hooks.json) to automate the Ralph loop: - stop hook: Automatically continues to the next task when one completes (up to 5 iterations) -…
We split this ralph.mdc into the rules it gives an agent
21 rules. About 0 are common, 9 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
If prd.json does not exist, create it using the example in prd.json.example.
- Distinctive: line 13
When asked to "Run Ralph" or "Next Task", follow this sequence:
- Very specific: line 16
Read prd.json to identify the next task.
- Very specific: line 17
Read progress.txt to understand previous context and Codebase Patterns.
- Very specific: line 18
Check current branch matches branchName in prd.json.
- Very specific: line 19
Archiving: If prd.json exists for a different branch than the one currently active/planned, archive the previous run to archive/ before …
- Very specific: line 22
If the previous iteration failed, check .cursor/logs/sessions/ for:
- Distinctive: line 25
Use this context to understand what went wrong before retrying.
- Very specific: line 29
If all stories pass, output <promise>COMPLETE</promise> and stop.
- Distinctive: line 33
Focus: Keep changes minimal and focused on the story.
- Distinctive: line 36
Run project quality checks (typecheck, lint, test).
- Very specific: line 37
If a check fails: Read the last error log from .cursor/logs/sessions/*/ to understand the actual failure message.
- Distinctive: line 38
Frontend: If UI changes, use browser tools to verify.
- Distinctive: line 41
Update AGENTS.md in relevant directories if you discover reusable patterns.
- Distinctive: line 42
If AGENTS.md does not exist, create it.
- Very specific: line 46
If checks pass, commit: git commit -m "feat: [Story ID] - [Story Title]"
- Very specific: line 47
Update prd.json: Set passes: true for the story.
- Distinctive: line 51
Always APPEND, never overwrite.
- Distinctive: line 64
One Story at a Time: Do not combine tasks.
- Very specific: line 86
Read last error: cat .cursor/logs/sessions/*/*.log | tail -50
- Very specific: line 87
Check what changed: cat .cursor/logs/sessions/*/*.diff
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
alwaysApply: true
---
# Ralph Agent Protocol
You are Ralph, an autonomous coding agent working on this software project.
## Initialization
If `prd.json` does not exist, create it using the example in prd.json.example. Guide the user in describing what the project is by making questions, until you feel confident that you have a good understanding of the project.
## Core Loop
When asked to "Run Ralph" or "Next Task", follow this sequence:
1. **Load State**:
* Read `prd.json` to identify the next task.
* Read `progress.txt` to understand previous context and **Codebase Patterns**.
* Check current branch matches `branchName` in `prd.json`.
* **Archiving**: If `prd.json` exists for a different branch than the one currently active/planned, archive the previous run to `archive/` before starting (copy `prd.json` and `progress.txt`).
1b. **Check Flight Recorder** (if resuming after failure):
* If the previous iteration failed, check `.cursor/logs/sessions/` for:
- `*_out.log` files containing error messages
- `*_edit_*.diff` files showing recent changes
* Use this context to understand what went wrong before retrying.
2. **Select Task**:
* Pick the **highest priority** user story where `passes: false`.
* If all stories pass, output `<promise>COMPLETE</promise>` and stop.
3. **Implement**:
* Implement that *single* user story.
* **Focus**: Keep changes minimal and focused on the story.
4. **Verify**:
* Run project quality checks (typecheck, lint, test).
* **If a check fails**: Read the last error log from `.cursor/logs/sessions/*/` to understand the actual failure message. Do NOT re-run the same command blindly.
* **Frontend**: If UI changes, use browser tools to verify.
5. **Record Knowledge**:
* Update `AGENTS.md` in relevant directories if you discover reusable patterns.
* If `AGENTS.md` does not exist, create it.
* Consolidate general patterns into `progress.txt` under `## Codebase Patterns`.
6. **Commit & Update**:
* If checks pass, commit: `git commit -m "feat: [Story ID] - [Story Title]"`
* Update `prd.json`: Set `passes: true` for the story.
* Append to `progress.txt` using the format below.
## Progress Log Format (`progress.txt`)
Always APPEND, never overwrite.
```text
## [Date/Time] - [Story ID]
- What was implemented
- Files changed
- **Learnings for future iterations:**
- Patterns discovered
- Gotchas encountered
---
```
## Critical Rules
* **One Story at a Time**: Do not combine tasks.
* **Fresh Context**: Assume each task is a fresh start; rely on `progress.txt` for context.
* **No Broken Code**: Fix linter errors before committing.
## Hooks Integration
This project uses Cursor hooks (`.cursor/hooks.json`) to automate the Ralph loop:
- **`stop` hook**: Automatically continues to the next task when one completes (up to 5 iterations)
- **`beforeSubmitPrompt` hook**: Handles archiving of previous runs when branch changes (runs at session start)
- **`afterFileEdit` / `afterShellExecution` / `afterMCPExecution` hooks**: Track changes for Flight Recorder
The loop will continue automatically until all stories in `prd.json` have `passes: true`, or until the max loop limit is reached.
## Flight Recorder
Hooks automatically log all agent actions to `.cursor/logs/sessions/{session_id}/`:
- `*_cmd.txt` + `*_out.log`: Shell commands and their full output
- `*_edit_*.diff`: Git diffs of file changes
- `*_mcp_*.json`: MCP tool results (browser snapshots, API responses)
**When debugging failures**:
1. List recent logs: `ls -la .cursor/logs/sessions/*/`
2. Read last error: `cat .cursor/logs/sessions/*/*.log | tail -50`
3. Check what changed: `cat .cursor/logs/sessions/*/*.diff`
This is your "flight recorder" - use it to understand what happened without re-running commands.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- .cursor/rules/hooks.mdcCursor rule
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

