Better Ralph – One Iteration (OpenClaw)
Execute one iteration of the Better Ralph workflow: pick the next PRD story, implement it, run quality checks, commit, update the PRD, and append progress. Uses only standard tools (read_file, write_file, edit, exec, git). No external runner or Aether-Claw required.
When to Use
- User says: "run better ralph", "do one better ralph iteration", "next prd story", "ralph loop", "implement next story from prd".
- Project has a
prd.json in the workspace root (see Output Format below for schema).
One-Iteration Workflow
Do these steps in order. Use only your standard file, exec, and git tools.
1. Read state
- Read
prd.json (workspace root). Parse the JSON.
- Read
progress.txt if it exists. If it has a section ## Codebase Patterns near the top (up to the next ## or end of file), use that as context for implementation patterns. Otherwise proceed without it.
2. Pick the next story
- From
prd.json.userStories, find all with passes === false.
- Sort by
priority ascending (lower number = higher priority).
- Take the first (highest priority incomplete story).
- If every story has
passes === true, reply: "All PRD stories are complete. Nothing left to do." and stop.
3. Ensure git branch
- Check current git branch (e.g. run
git branch --show-current or use your git tool).
- If
prd.json has a branchName and it differs from the current branch, checkout or create that branch (e.g. git checkout -b <branchName> or git checkout <branchName>).
4. Implement the story
- Story = the one you picked. It has:
id, title, description, acceptanceCriteria, priority, passes.
- Implement the story: write or edit code so that every item in
acceptanceCriteria is satisfied.
- Work on this story only. Do not start the next story.
5. Run quality checks
- Run the project’s quality commands (e.g.
npm test, npm run lint, npm run typecheck, or whatever the project uses).
- If any check fails, do not commit. Tell the user what failed and stop. Do not update
prd.json or progress.txt for a failed story.
6. Commit (only if checks passed)
- Stage all changes (e.g.
git add -A or your git tool’s equivalent).
- Commit with message exactly:
feat: [Story ID] - [Story Title]
Example: feat: US-002 - Display priority on task cards
7. Mark story passed in prd.json
- Read
prd.json again (in case it changed).
- Find the user story with the same
id you just completed. Set its passes to true.
- Write the full updated
prd.json back (preserve structure and other fields; only change that story’s passes).
8. Append progress to progress.txt
- Append (do not overwrite) a new block to
progress.txt with this format:
## [Current date/time] - [Story ID]
- What was implemented (1–2 sentences)
- Files changed (list paths)
- **Learnings for future iterations:**
- Patterns or gotchas (e.g. "this codebase uses X for Y", "remember to update Z when changing W")
---
- If
progress.txt does not exist, create it with a first line like # Better Ralph Progress then the block above.
9. Report to user
- Say which story you completed (ID and title) and that you updated the PRD and progress.
- If there are still stories with
passes === false, say: "Run another iteration to do the next story." If all are complete, say: "All PRD stories are complete."
prd.json format
If the user wants to create a new prd.json (no file yet), create it with this shape:
{
"project": "ProjectName",
"branchName": "ralph/feature-kebab-case",
"description": "Short feature description",
"userStories": [
{
"id": "US-001",
"title": "Short title",
"description": "As a [role], I want [thing] so that [benefit].",
"acceptanceCriteria": [
"Verifiable criterion 1",
"Verifiable criterion 2",
"Typecheck passes"
],
"priority": 1,
"passes": false,
"notes": ""
}
]
}
- priority: Lower number = higher priority. Order by dependency (e.g. schema before UI).
- passes: Start as
false; set to true only after the story is implemented and committed.
- acceptanceCriteria: Each item must be checkable (e.g. "Typecheck passes", "Tests pass").
Codebase Patterns (progress.txt)
Optionally keep a Codebase Patterns section at the top of progress.txt so future iterations (or you in the next run) see it first:
# Better Ralph Progress
## Codebase Patterns
- Use X for Y in this codebase
- Always run Z after changing W
- Tests require PORT=3000
---
When you read progress.txt at the start of an iteration, use this section as context. When you discover a reusable pattern, add it here (edit the top of the file and keep the rest intact). Do not put story-specific details in Codebase Patterns.
Rules
- One story per invocation. Do not implement multiple stories in one go.
- Do not commit failing code. Only commit after quality checks pass.
- Do not mark a story as passed if you did not commit (e.g. checks failed).
- Append to progress.txt; never replace the whole file (except when creating it for the first time).
- Keep changes minimal and focused on the current story’s acceptance criteria.
Checklist (one iteration)
1---2name: better-ralph3description: Run one Better Ralph iteration: PRD-driven autonomous coding. Read prd.json, pick next story, implement it, run checks, commit, mark story passed, append progress. Uses only standard OpenClaw tools (read, write, exec, git). Triggers on: run better ralph, better ralph iteration, do one ralph story, next prd story, ralph loop.4---5
6# Better Ralph – One Iteration (OpenClaw)
7
8Execute **one iteration** of the Better Ralph workflow: pick the next PRD story, implement it, run quality checks, commit, update the PRD, and append progress. Uses only standard tools (read_file, write_file, edit, exec, git). No external runner or Aether-Claw required.
9
10---
11
12## When to Use
13
14- User says: "run better ralph", "do one better ralph iteration", "next prd story", "ralph loop", "implement next story from prd".
15- Project has a `prd.json` in the workspace root (see Output Format below for schema).
16
17---
18
19## One-Iteration Workflow
20
21Do these steps in order. Use **only** your standard file, exec, and git tools.
22
23### 1. Read state
24
25- **Read** `prd.json` (workspace root). Parse the JSON.
26- **Read** `progress.txt` if it exists. If it has a section `## Codebase Patterns` near the top (up to the next `##` or end of file), use that as context for implementation patterns. Otherwise proceed without it.
27
28### 2. Pick the next story
29
30- From `prd.json.userStories`, find all with `passes === false`.
31- Sort by `priority` ascending (lower number = higher priority).
32- Take the **first** (highest priority incomplete story).
33- If **every** story has `passes === true`, reply: "All PRD stories are complete. Nothing left to do." and stop.
34
35### 3. Ensure git branch
36
37- Check current git branch (e.g. run `git branch --show-current` or use your git tool).
38- If `prd.json` has a `branchName` and it differs from the current branch, checkout or create that branch (e.g. `git checkout -b <branchName>` or `git checkout <branchName>`).
39
40### 4. Implement the story
41
42- **Story** = the one you picked. It has: `id`, `title`, `description`, `acceptanceCriteria`, `priority`, `passes`.
43- Implement the story: write or edit code so that every item in `acceptanceCriteria` is satisfied.
44- Work on **this story only**. Do not start the next story.
45
46### 5. Run quality checks
47
48- Run the project’s quality commands (e.g. `npm test`, `npm run lint`, `npm run typecheck`, or whatever the project uses).
49- If **any check fails**, do **not** commit. Tell the user what failed and stop. Do not update `prd.json` or `progress.txt` for a failed story.
50
51### 6. Commit (only if checks passed)
52
53- Stage all changes (e.g. `git add -A` or your git tool’s equivalent).
54- Commit with message exactly: `feat: [Story ID] - [Story Title]`
55 Example: `feat: US-002 - Display priority on task cards`
56
57### 7. Mark story passed in prd.json
58
59- **Read** `prd.json` again (in case it changed).
60- Find the user story with the same `id` you just completed. Set its `passes` to `true`.
61- **Write** the full updated `prd.json` back (preserve structure and other fields; only change that story’s `passes`).
62
63### 8. Append progress to progress.txt
64
65- **Append** (do not overwrite) a new block to `progress.txt` with this format:
66
67```
68## [Current date/time] - [Story ID]
69- What was implemented (1–2 sentences)
70- Files changed (list paths)
71- **Learnings for future iterations:**
72 - Patterns or gotchas (e.g. "this codebase uses X for Y", "remember to update Z when changing W")
73---
74```
75
76- If `progress.txt` does not exist, create it with a first line like `# Better Ralph Progress` then the block above.
77
78### 9. Report to user
79
80- Say which story you completed (ID and title) and that you updated the PRD and progress.
81- If there are still stories with `passes === false`, say: "Run another iteration to do the next story." If all are complete, say: "All PRD stories are complete."
82
83---
84
85## prd.json format
86
87If the user wants to **create** a new `prd.json` (no file yet), create it with this shape:
88
89```json
90{
91 "project": "ProjectName",
92 "branchName": "ralph/feature-kebab-case",
93 "description": "Short feature description",
94 "userStories": [
95 {
96 "id": "US-001",
97 "title": "Short title",
98 "description": "As a [role], I want [thing] so that [benefit].",
99 "acceptanceCriteria": [
100 "Verifiable criterion 1",
101 "Verifiable criterion 2",
102 "Typecheck passes"
103 ],
104 "priority": 1,
105 "passes": false,
106 "notes": ""
107 }
108 ]
109}
110```
111
112- **priority**: Lower number = higher priority. Order by dependency (e.g. schema before UI).
113- **passes**: Start as `false`; set to `true` only after the story is implemented and committed.
114- **acceptanceCriteria**: Each item must be checkable (e.g. "Typecheck passes", "Tests pass").
115
116---
117
118## Codebase Patterns (progress.txt)
119
120Optionally keep a **Codebase Patterns** section at the **top** of `progress.txt` so future iterations (or you in the next run) see it first:
121
122```
123# Better Ralph Progress
124
125## Codebase Patterns
126- Use X for Y in this codebase
127- Always run Z after changing W
128- Tests require PORT=3000
129
130---
131```
132
133When you read `progress.txt` at the start of an iteration, use this section as context. When you discover a **reusable** pattern, add it here (edit the top of the file and keep the rest intact). Do not put story-specific details in Codebase Patterns.
134
135---
136
137## Rules
138
139- **One story per invocation.** Do not implement multiple stories in one go.
140- **Do not commit failing code.** Only commit after quality checks pass.
141- **Do not mark a story as passed** if you did not commit (e.g. checks failed).
142- **Append** to progress.txt; never replace the whole file (except when creating it for the first time).
143- Keep changes **minimal and focused** on the current story’s acceptance criteria.
144
145---
146
147## Checklist (one iteration)
148
149- [ ] Read prd.json and progress.txt (and Codebase Patterns if present)
150- [ ] Picked next story (passes=false, lowest priority number)
151- [ ] Git branch matches prd.json.branchName
152- [ ] Implemented story and satisfied all acceptance criteria
153- [ ] Quality checks passed (test/lint/typecheck)
154- [ ] Committed with message `feat: [ID] - [Title]`
155- [ ] Set that story’s passes to true in prd.json
156- [ ] Appended progress block to progress.txt