ralphing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ralphing

运行Ralph自主编码循环

Ralph is an autonomous AI coding loop that ships features while you sleep. Each iteration runs in a fresh context window, while memory persists through git history and text files.
Ralph是一款自主AI编码循环工具,能在你休息时完成功能开发并交付。每次迭代都会在全新的上下文窗口中运行,而记忆则通过git历史记录和文本文件得以保留。

When to Use

使用场景

When the user wants to implement a multi-story feature autonomously, or mentions "ralph", "ralphing", or "autonomous loop".
当用户希望自主实现多需求故事的功能,或者提到“ralph”、“ralphing”或“自主循环”时使用。

Workflow

工作流程

Step 1: Get the PRD

步骤1:获取PRD文件

The user provides a PRD file, or you help them create one. Ask:
  1. Do you have a PRD already, or should we create one together?
  2. What's the repo path?
  3. What's the test command? (e.g.,
    bundle exec rake
    ,
    npm test
    )
  4. How many iterations max? (default: 25)
用户提供PRD文件,或者你协助他们创建。请询问:
  1. 你已有PRD文件,还是需要我们一起创建?
  2. 仓库路径是什么?
  3. 测试命令是什么?(例如:
    bundle exec rake
    npm test
  4. 最大迭代次数是多少?(默认值:25)

PRD Format

PRD格式

markdown
undefined
markdown
undefined

PRD

PRD

Branch:
<branch-name>
Branch:
<branch-name>

Stories

Stories

US-001: <Story title>

US-001: <Story title>

  • <Acceptance criterion>
  • <Acceptance criterion>
  • <Acceptance criterion>
  • <Acceptance criterion>

US-002: <Story title>

US-002: <Story title>

  • <Acceptance criterion>

Guidelines for stories:
- **Small**: Must fit in one context window
- **Explicit criteria**: Avoid vague ("Users can log in"), prefer specific checks
- Story order = priority (first = highest)

Note: Ralph is typically run in a git worktree. If already on the correct branch (or detached HEAD), the branch checkout is skipped.
  • <Acceptance criterion>

需求故事编写准则:
- **粒度要小**:必须能容纳在一个上下文窗口中
- **验收标准明确**:避免模糊表述(如“用户可以登录”),优先使用可具体验证的检查项
- 故事顺序=优先级(第一个故事优先级最高)

注意:Ralph通常在git worktree中运行。如果已处于正确分支(或分离HEAD状态),则会跳过分支检出步骤。

Step 2: Start the Loop

步骤2:启动循环

bash
~/.claude/skills/ralphing/assets/ralph.sh start <repo_path> <prd.md> [max_iterations] [test_cmd]
This returns a session directory (e.g.,
/tmp/ralph/ABC123-...
) and runs the loop in the background.
bash
~/.claude/skills/ralphing/assets/ralph.sh start <repo_path> <prd.md> [max_iterations] [test_cmd]
这会生成一个会话目录(例如:
/tmp/ralph/ABC123-...
)并在后台运行循环。

Step 3: Monitor Progress

步骤3:监控进度

Poll the session status periodically:
bash
~/.claude/skills/ralphing/assets/ralph.sh status <ralph_dir>
This outputs:
  • status
    :
    running
    ,
    complete
    , or
    failed
  • iteration
    : current/max iterations
  • Full contents of
    progress.txt
Keep polling until status is
complete
or
failed
.
定期轮询会话状态:
bash
~/.claude/skills/ralphing/assets/ralph.sh status <ralph_dir>
该命令会输出:
  • status
    running
    (运行中)、
    complete
    (已完成)或
    failed
    (失败)
  • iteration
    :当前/最大迭代次数
  • progress.txt
    的完整内容
持续轮询直到状态变为
complete
failed

How the Loop Works

循环工作原理

  1. start
    copies PRD, generates prompt, checks out branch (if needed), and spawns background process
  2. Background loop: agent implements story -> commits -> runs tests
  3. If tests fail, reverts commit and retries (progress.txt preserved)
  4. Exits when agent signals
    <promise>COMPLETE</promise>
    or max iterations reached
  5. Parent agent polls
    status
    to observe progress without blocking
  1. start
    命令会复制PRD、生成提示词、检出分支(如有需要)并启动后台进程
  2. 后台循环流程:Agent实现需求故事 -> 提交代码 -> 运行测试
  3. 如果测试失败,会回滚提交并重试(
    progress.txt
    内容会保留)
  4. 当Agent发出
    <promise>COMPLETE</promise>
    信号或达到最大迭代次数时,循环退出
  5. 父Agent通过轮询
    status
    来观察进度,不会造成阻塞

Resources

相关资源

  • assets/ralph.sh
    - the loop script (start/status commands)
  • assets/prompt.md
    - prompt template (uses
    <RALPH_DIR>
    placeholder)
  • assets/ralph.sh
    - 循环脚本(包含start/status命令)
  • assets/prompt.md
    - 提示词模板(使用
    <RALPH_DIR>
    占位符)