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 (readfile, writefile, 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: INLINECODE27
Example: INLINECODE28
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:
CODEBLOCK0
- - 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:
CODEBLOCK1
- - 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:
CODEBLOCK2
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)
- - [ ] Read prd.json and progress.txt (and Codebase Patterns if present)
- [ ] Picked next story (passes=false, lowest priority number)
- [ ] Git branch matches prd.json.branchName
- [ ] Implemented story and satisfied all acceptance criteria
- [ ] Quality checks passed (test/lint/typecheck)
- [ ] Committed with message INLINECODE44
- [ ] Set that story’s passes to true in prd.json
- [ ] Appended progress block to progress.txt
Better Ralph – 单次迭代 (OpenClaw)
执行 一次迭代 的 Better Ralph 工作流:选取下一个 PRD 故事,实现它,运行质量检查,提交,更新 PRD,并追加进度。仅使用标准工具(readfile、writefile、edit、exec、git)。无需外部运行器或 Aether-Claw。
使用时机
- - 用户说:run better ralph、do one better ralph iteration、next prd story、ralph loop、implement next story from prd。
- 项目在工作区根目录下包含 prd.json(架构见下方输出格式)。
单次迭代工作流
按顺序执行以下步骤。仅使用你的标准文件、exec 和 git 工具。
1. 读取状态
- - 读取 prd.json(工作区根目录)。解析 JSON。
- 读取 progress.txt(如果存在)。如果其顶部附近(直到下一个 ## 或文件末尾)有 ## Codebase Patterns 部分,则将其作为实现模式的上下文。否则,无需该部分继续执行。
2. 选取下一个故事
- - 从 prd.json.userStories 中,找到所有 passes === false 的故事。
- 按 priority 升序排序(数字越小 = 优先级越高)。
- 取第一个(优先级最高的未完成故事)。
- 如果每个故事的 passes 都是 true,则回复:所有 PRD 故事已完成。无需再做任何操作。 并停止。
3. 确保 git 分支
- - 检查当前 git 分支(例如运行 git branch --show-current 或使用你的 git 工具)。
- 如果 prd.json 包含 branchName 且与当前分支不同,则切换或创建该分支(例如 git checkout -b 或 git checkout )。
4. 实现故事
- - 故事 = 你选取的那个。它包含:id、title、description、acceptanceCriteria、priority、passes。
- 实现故事:编写或编辑代码,使 acceptanceCriteria 中的每一项都得到满足。
- 仅处理这个故事。不要开始下一个故事。
5. 运行质量检查
- - 运行项目的质量命令(例如 npm test、npm run lint、npm run typecheck,或项目使用的任何命令)。
- 如果任何检查失败,则不要提交。告知用户失败的内容并停止。对于失败的故事,不要更新 prd.json 或 progress.txt。
6. 提交(仅在检查通过时)
- - 暂存所有更改(例如 git add -A 或你的 git 工具的等效操作)。
- 提交信息必须为:feat: [故事ID] - [故事标题]
示例:feat: US-002 - Display priority on task cards
7. 在 prd.json 中将故事标记为通过
- - 再次读取 prd.json(以防它发生变化)。
- 找到与你刚完成的故事具有相同 id 的用户故事。将其 passes 设置为 true。
- 写回完整的更新后的 prd.json(保留结构和其他字段;仅更改该故事的 passes)。
8. 将进度追加到 progress.txt
- - 追加(不要覆盖)一个新块到 progress.txt,格式如下:
[当前日期/时间] - [故事ID]
- - 实现了什么(1-2句话)
- 更改的文件(列出路径)
- 对未来迭代的启示:
- 模式或注意事项(例如此代码库使用 X 来实现 Y、更改 W 时记得更新 Z)
- - 如果 progress.txt 不存在,则创建它,第一行为 # Better Ralph Progress,然后跟上上述块。
9. 向用户报告
- - 告知用户你完成了哪个故事(ID 和标题),以及你更新了 PRD 和进度。
- 如果仍有 passes === false 的故事,则说:运行另一次迭代以处理下一个故事。 如果全部完成,则说:所有 PRD 故事已完成。
prd.json 格式
如果用户想要创建一个新的 prd.json(尚无文件),请使用以下形状创建:
json
{
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:数字越小 = 优先级越高。按依赖关系排序(例如模式在 UI 之前)。
- passes:初始为 false;仅在故事实现并提交后设置为 true。
- acceptanceCriteria:每一项都必须是可检查的(例如类型检查通过、测试通过)。
代码库模式 (progress.txt)
可选地在 progress.txt 的顶部保留一个 Codebase Patterns 部分,以便未来的迭代(或你在下一次运行时)首先看到它:
Better Ralph Progress
Codebase Patterns
- - 在此代码库中使用 X 来实现 Y
- 更改 W 后始终运行 Z
- 测试需要 PORT=3000
当你在迭代开始时读取 progress.txt 时,使用此部分作为上下文。当你发现一个
可重用的模式时,将其添加到此部分(编辑文件顶部并保持其余部分不变)。不要将故事特定的细节放入 Codebase Patterns。
规则
- - 每次调用只处理一个故事。 不要一次性实现多个故事。
- 不要提交失败的代码。 仅在质量检查通过后提交。
- 如果你没有提交(例如检查失败),不要将故事标记为通过。
- 追加到 progress.txt;永远不要替换整个文件(首次创建时除外)。
- 保持更改最小化且专注于当前故事的验收标准。
检查清单(单次迭代)
- - [ ] 读取 prd.json 和 progress.txt(以及 Codebase Patterns,如果存在)
- [ ] 选取下一个故事(passes=false,优先级数字最低)
- [ ] Git 分支与 prd.json.branchName 匹配
- [ ] 实现故事并满足所有验收标准
- [ ] 质量检查通过(测试/代码检查/类型检查)
- [ ] 使用信息 feat: [ID] - [Title] 提交
- [ ] 在 prd.json 中将该故事的 passes 设置为 true
- [ ] 将进度块追加到 progress.txt