iterative-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIterative Development Skill (Ralph Wiggum Integration)
迭代开发技能(Ralph Wiggum 集成)
Load with: base.md
Concept: Self-referential development loops where Claude iterates on the same task until completion criteria are met. Based on the Ralph Wiggum plugin.
Core Philosophy
核心理念
┌─────────────────────────────────────────────────────────────┐
│ ITERATION > PERFECTION │
│ ───────────────────────────────────────────────────────── │
│ Don't aim for perfect on first try. │
│ Let the loop refine the work. Each iteration builds on │
│ previous attempts visible in files and git history. │
├─────────────────────────────────────────────────────────────┤
│ FAILURES ARE DATA │
│ ───────────────────────────────────────────────────────── │
│ Failed tests, lint errors, type mismatches are signals. │
│ Use them to guide the next iteration. │
├─────────────────────────────────────────────────────────────┤
│ CLEAR COMPLETION CRITERIA │
│ ───────────────────────────────────────────────────────── │
│ Define exactly what "done" looks like. │
│ Tests passing. Coverage met. Lint clean. │
│ No ambiguity about when to stop. │
└─────────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────────┐
│ ITERATION > PERFECTION │
│ ───────────────────────────────────────────────────────── │
│ 不要追求一次就做到完美。 │
│ 让循环来优化工作成果。每次迭代都基于文件和 git 历史中可见的│
│ 之前的尝试进行构建。 │
├─────────────────────────────────────────────────────────────┤
│ FAILURES ARE DATA │
│ ───────────────────────────────────────────────────────── │
│ 测试失败、Lint 错误、类型不匹配都是信号。 │
│ 利用它们来指导下一次迭代。 │
├─────────────────────────────────────────────────────────────┤
│ CLEAR COMPLETION CRITERIA │
│ ───────────────────────────────────────────────────────── │
│ 准确定义“完成”的标准。 │
│ 测试通过、达到覆盖率要求、Lint 检查无问题。 │
│ 停止时机清晰明确,无歧义。 │
└─────────────────────────────────────────────────────────────┘Installing Ralph Wiggum Plugin
安装 Ralph Wiggum 插件
bash
undefinedbash
undefinedClone the plugin
Clone the plugin
git clone https://github.com/anthropics/claude-code.git /tmp/claude-code
cp -r /tmp/claude-code/plugins/ralph-wiggum ~/.claude/plugins/
git clone https://github.com/anthropics/claude-code.git /tmp/claude-code
cp -r /tmp/claude-code/plugins/ralph-wiggum ~/.claude/plugins/
Or add to project-local plugins
Or add to project-local plugins
mkdir -p .claude/plugins
cp -r /tmp/claude-code/plugins/ralph-wiggum .claude/plugins/
---mkdir -p .claude/plugins
cp -r /tmp/claude-code/plugins/ralph-wiggum .claude/plugins/
---How It Works
工作原理
┌─────────────────────────────────────────────────────────────┐
│ 1. /ralph-loop "Your task prompt" --max-iterations 20 │
├─────────────────────────────────────────────────────────────┤
│ 2. Claude works on task │
├─────────────────────────────────────────────────────────────┤
│ 3. Claude attempts to exit │
├─────────────────────────────────────────────────────────────┤
│ 4. Stop hook blocks exit, feeds SAME PROMPT back │
├─────────────────────────────────────────────────────────────┤
│ 5. Claude sees modified files + git history from before │
├─────────────────────────────────────────────────────────────┤
│ 6. Claude iterates and improves │
├─────────────────────────────────────────────────────────────┤
│ 7. Loop continues until: │
│ • Completion promise detected: <promise>DONE</promise> │
│ • Max iterations reached │
└─────────────────────────────────────────────────────────────┘Key insight: The prompt never changes. Only the file state evolves. Claude reads its own previous work and refines it.
┌─────────────────────────────────────────────────────────────┐
│ 1. /ralph-loop "Your task prompt" --max-iterations 20 │
├─────────────────────────────────────────────────────────────┤
│ 2. Claude works on task │
├─────────────────────────────────────────────────────────────┤
│ 3. Claude attempts to exit │
├─────────────────────────────────────────────────────────────┤
│ 4. Stop hook blocks exit, feeds SAME PROMPT back │
├─────────────────────────────────────────────────────────────┤
│ 5. Claude sees modified files + git history from before │
├─────────────────────────────────────────────────────────────┤
│ 6. Claude iterates and improves │
├─────────────────────────────────────────────────────────────┤
│ 7. Loop continues until: │
│ • Completion promise detected: <promise>DONE</promise> │
│ • Max iterations reached │
└─────────────────────────────────────────────────────────────┘关键洞察: 提示词始终保持不变,只有文件状态会演进。Claude 会读取自己之前的工作成果并进行优化。
TDD-Integrated Prompt Templates
集成TDD的提示词模板
Feature Development (TDD Loop)
功能开发(TDD循环)
bash
/ralph-loop "bash
/ralph-loop "Task: [Feature Name]
任务: [功能名称]
Requirements
需求
- [Requirement 1]
- [Requirement 2]
- [Requirement 3]
- [需求1]
- [需求2]
- [需求3]
TDD Workflow (MUST FOLLOW)
TDD工作流(必须遵循)
- Write failing tests based on requirements
- Run tests - verify they FAIL (RED phase)
- Implement minimum code to pass tests
- Run tests - verify they PASS (GREEN phase)
- Run lint and typecheck
- If any failures, debug and fix
- Repeat until all green
- 根据需求编写失败的测试用例
- 运行测试 - 验证测试失败(RED阶段)
- 实现最小化代码以通过测试
- 运行测试 - 验证测试通过(GREEN阶段)
- 运行Lint检查和类型校验
- 如果有任何失败,进行调试和修复
- 重复直至全部通过
Completion Criteria
完成标准
- All tests passing
- Coverage >= 80%
- Lint clean (no errors)
- TypeScript/type check passing
- 所有测试通过
- 测试覆盖率 ≥ 80%
- Lint检查无错误
- TypeScript/类型校验通过
Exit Condition
退出条件
When ALL criteria above are TRUE, output:
<promise>ALL TESTS PASSING AND LINT CLEAN</promise>
" --completion-promise "ALL TESTS PASSING AND LINT CLEAN" --max-iterations 30
undefined当上述所有标准均满足时,输出:
<promise>ALL TESTS PASSING AND LINT CLEAN</promise>
" --completion-promise "ALL TESTS PASSING AND LINT CLEAN" --max-iterations 30
undefinedBug Fix (TDD Loop)
Bug修复(TDD循环)
bash
/ralph-loop "bash
/ralph-loop "Bug: [Bug Description]
Bug: [Bug描述]
Reproduction
复现步骤
- [Step 1]
- [Step 2]
- Observe: [Wrong behavior]
- Expected: [Correct behavior]
- [步骤1]
- [步骤2]
- 观察到:[错误行为]
- 预期:[正确行为]
TDD Bug Fix Workflow (MUST FOLLOW)
TDD Bug修复工作流(必须遵循)
- Run existing tests - note if any catch the bug
- Write a failing test that reproduces the bug
- Run test - verify it FAILS (proves test catches bug)
- Fix the bug with minimum code change
- Run test - verify it PASSES
- Run FULL test suite for regressions
- Run lint and typecheck
- If any failures, debug and fix
- Repeat until all green
- 运行现有测试 - 记录是否有测试能捕获该Bug
- 编写一个能复现Bug的失败测试用例
- 运行测试 - 验证测试失败(证明测试能捕获Bug)
- 用最小化代码变更修复Bug
- 运行测试 - 验证测试通过
- 运行完整测试套件检查是否有回归
- 运行Lint检查和类型校验
- 如果有任何失败,进行调试和修复
- 重复直至全部通过
Completion Criteria
完成标准
- New test for bug exists
- New test passes
- All existing tests pass
- No regressions
- Lint clean
- 存在针对该Bug的新测试用例
- 新测试用例通过
- 所有现有测试通过
- 无回归问题
- Lint检查无错误
Exit Condition
退出条件
When ALL criteria are TRUE, output:
<promise>BUG FIXED WITH TEST</promise>
" --completion-promise "BUG FIXED WITH TEST" --max-iterations 25
undefined当所有标准均满足时,输出:
<promise>BUG FIXED WITH TEST</promise>
" --completion-promise "BUG FIXED WITH TEST" --max-iterations 25
undefinedRefactoring (Safe Loop)
代码重构(安全循环)
bash
/ralph-loop "bash
/ralph-loop "Refactor: [What to refactor]
重构: [重构内容]
Goals
目标
- [Goal 1: e.g., Extract function, reduce complexity]
- [Goal 2: e.g., Improve naming]
- [Goal 3: e.g., Split file if > 200 lines]
- [目标1:例如,提取函数、降低复杂度]
- [目标2:例如,优化命名]
- [目标3:例如,若文件超过200行则拆分]
Safety Constraints
安全约束
- All existing tests MUST continue to pass
- No behavior changes (refactor only)
- Coverage must not decrease
- 所有现有测试必须继续通过
- 不得改变行为(仅重构)
- 测试覆盖率不得降低
Workflow
工作流
- Run all tests - establish baseline (must pass)
- Make ONE refactoring change
- Run tests - must still pass
- Run lint and typecheck
- If failures, REVERT and try different approach
- Commit working refactor
- Repeat for next change
- 运行所有测试 - 建立基准(必须全部通过)
- 进行一次重构变更
- 运行测试 - 必须仍然通过
- 运行Lint检查和类型校验
- 如果失败,回滚并尝试其他方法
- 提交可行的重构变更
- 重复进行下一次变更
Completion Criteria
完成标准
- All refactoring goals met
- All tests passing
- Coverage same or higher
- Lint clean
- 所有重构目标达成
- 所有测试通过
- 测试覆盖率保持不变或提升
- Lint检查无错误
Exit Condition
退出条件
<promise>REFACTOR COMPLETE ALL TESTS GREEN</promise>
" --completion-promise "REFACTOR COMPLETE ALL TESTS GREEN" --max-iterations 20
undefined<promise>REFACTOR COMPLETE ALL TESTS GREEN</promise>
" --completion-promise "REFACTOR COMPLETE ALL TESTS GREEN" --max-iterations 20
undefinedAPI Development
API开发
bash
/ralph-loop "bash
/ralph-loop "Task: Build [API Name] API
任务: 构建 [API名称] API
Endpoints Required
所需端点
- POST /api/resource - Create
- GET /api/resource - List
- GET /api/resource/:id - Get one
- PUT /api/resource/:id - Update
- DELETE /api/resource/:id - Delete
- POST /api/resource - 创建
- GET /api/resource - 列表
- GET /api/resource/:id - 获取单个资源
- PUT /api/resource/:id - 更新
- DELETE /api/resource/:id - 删除
Requirements
需求
- Input validation (Zod/Pydantic)
- Error handling with proper status codes
- Tests for each endpoint
- OpenAPI/Swagger docs
- 输入验证(Zod/Pydantic)
- 带有正确状态码的错误处理
- 每个端点的测试用例
- OpenAPI/Swagger文档
TDD Workflow
TDD工作流
- Write integration tests for each endpoint
- Run tests - all should FAIL
- Implement endpoints one by one
- Run tests after each endpoint
- Continue until all pass
- Add validation and error handling
- Run full test suite
- Generate API docs
- 为每个端点编写集成测试
- 运行测试 - 全部应该失败
- 逐个实现端点
- 每个端点实现后运行测试
- 持续直至全部通过
- 添加验证和错误处理
- 运行完整测试套件
- 生成API文档
Completion Criteria
完成标准
- All endpoint tests passing
- Input validation working
- Error responses correct
- Coverage >= 80%
- Lint clean
- 所有端点测试通过
- 输入验证正常工作
- 错误响应正确
- 测试覆盖率 ≥ 80%
- Lint检查无错误
Exit Condition
退出条件
<promise>API COMPLETE WITH TESTS</promise>
" --completion-promise "API COMPLETE WITH TESTS" --max-iterations 40
---<promise>API COMPLETE WITH TESTS</promise>
" --completion-promise "API COMPLETE WITH TESTS" --max-iterations 40
---Prompt Writing Rules
提示词编写规则
1. Clear Completion Criteria (REQUIRED)
1. 明确的完成标准(必填)
markdown
❌ BAD: "Build a todo API and make it good."
✅ GOOD:markdown
❌ 错误示例: "构建一个待办事项API并确保质量良好。"
✅ 正确示例:Completion Criteria
完成标准
- CRUD endpoints implemented
- All tests passing
- Input validation working
- Coverage >= 80%
- Lint clean
- 实现CRUD端点
- 所有测试通过
- 输入验证正常工作
- 测试覆盖率 ≥ 80%
- Lint检查无错误
Exit Condition
退出条件
<promise>ALL TESTS PASSING</promise>
undefined<promise>ALL TESTS PASSING</promise>
undefined2. Always Set Max Iterations
2. 始终设置最大迭代次数
bash
undefinedbash
undefined❌ DANGEROUS - runs forever
❌ 危险 - 循环会无限运行
/ralph-loop "Build something"
/ralph-loop "构建某个功能"
✅ SAFE - stops after 30 iterations
✅ 安全 - 30次迭代后停止
/ralph-loop "Build something" --max-iterations 30
undefined/ralph-loop "构建某个功能" --max-iterations 30
undefined3. Include TDD in Every Prompt
3. 在提示词中包含TDD流程
markdown
undefinedmarkdown
undefinedTDD Workflow (MUST FOLLOW)
TDD工作流(必须遵循)
- Write failing tests first
- Verify tests fail
- Implement feature
- Verify tests pass
- Run lint + typecheck
- Repeat if failures
undefined- 先编写失败的测试用例
- 验证测试失败
- 实现功能
- 验证测试通过
- 运行Lint检查 + 类型校验
- 如果失败则重复
undefined4. Break Large Tasks into Phases
4. 将大型任务拆分为多个阶段
markdown
undefinedmarkdown
undefinedPhase 1: Authentication
阶段1: 身份验证
- Login endpoint with JWT
- Tests passing
- Output: <promise>AUTH COMPLETE</promise>
- 基于JWT的登录端点
- 测试通过
- 输出: <promise>AUTH COMPLETE</promise>
Phase 2: User CRUD (after Phase 1)
阶段2: 用户CRUD(阶段1完成后)
- User endpoints
- Tests passing
- Output: <promise>USERS COMPLETE</promise>
- 用户端点
- 测试通过
- 输出: <promise>USERS COMPLETE</promise>
Phase 3: Products (after Phase 2)
阶段3: 产品管理(阶段2完成后)
...
undefined...
undefined5. Include Fallback Behavior
5. 包含回退行为
markdown
undefinedmarkdown
undefinedIf Stuck After 15 Iterations
若15次迭代后仍受阻
- Document what's blocking progress
- List approaches attempted
- Suggest alternative approaches
- Output: <promise>BLOCKED NEED HELP</promise>
---- 记录阻碍进度的问题
- 列出已尝试的方法
- 建议替代方案
- 输出: <promise>BLOCKED NEED HELP</promise>
---Error Classification (Critical for Loops)
错误分类(循环的关键)
Not all test failures are equal. Claude MUST classify errors before iterating.
并非所有测试失败都相同。Claude在迭代前必须对错误进行分类。
Error Types
错误类型
| Type | Examples | Claude Can Fix? | Action |
|---|---|---|---|
| Code Error | Logic bug, wrong algorithm, missing validation | ✅ YES | Continue loop |
| Type Error | Wrong types, missing properties | ✅ YES | Continue loop |
| Test Error | Wrong assertion, incomplete test | ✅ YES | Continue loop |
| Access Error | Missing API key, DB connection refused | ❌ NO | STOP + report |
| Permission Error | File access denied, auth failed | ❌ NO | STOP + report |
| Environment Error | Missing dependency, wrong Node version | ❌ NO | STOP + report |
| Network Error | Service unreachable, timeout | ❌ NO | STOP + report |
| 类型 | 示例 | Claude能否修复? | 操作 |
|---|---|---|---|
| 代码错误 | 逻辑Bug、错误算法、缺失验证 | ✅ 是 | 继续循环 |
| 类型错误 | 错误类型、缺失属性 | ✅ 是 | 继续循环 |
| 测试错误 | 错误断言、测试不完整 | ✅ 是 | 继续循环 |
| 访问错误 | 缺失API密钥、数据库连接拒绝 | ❌ 否 | 停止 + 报告 |
| 权限错误 | 文件访问被拒绝、身份验证失败 | ❌ 否 | 停止 + 报告 |
| 环境错误 | 缺失依赖、Node版本错误 | ❌ 否 | 停止 + 报告 |
| 网络错误 | 服务不可达、超时 | ❌ 否 | 停止 + 报告 |
Error Detection Pattern
错误检测模式
markdown
undefinedmarkdown
undefinedBefore Each Iteration
每次迭代前
-
Run tests
-
If tests fail, classify the error:Code/Logic Error? (Claude can fix)
- "Expected X but received Y"
- "TypeError: cannot read property"
- "AssertionError" → CONTINUE LOOP
Access/Environment Error? (Human must fix)- "ECONNREFUSED" (DB not running)
- "401 Unauthorized" (bad API key)
- "ENOENT" (file/path not found)
- "EACCES" (permission denied)
- "MODULE_NOT_FOUND" (missing package)
- "Connection timeout" → STOP LOOP + OUTPUT BLOCKER
undefined-
运行测试
-
如果测试失败,对错误进行分类:代码/逻辑错误?(Claude可修复)
- "预期X但收到Y"
- "TypeError: 无法读取属性"
- "AssertionError" → 继续循环
访问/环境错误?(需人工修复)- "ECONNREFUSED"(数据库未运行)
- "401 Unauthorized"(无效API密钥)
- "ENOENT"(文件/路径不存在)
- "EACCES"(权限被拒绝)
- "MODULE_NOT_FOUND"(缺失包)
- "连接超时" → 停止循环 + 输出阻碍信息
undefinedBlocker Report Format
阻碍报告格式
When Claude detects an access/environment error, output this IMMEDIATELY:
markdown
undefined当Claude检测到访问/环境错误时,立即输出以下内容:
markdown
undefined🛑 LOOP BLOCKED - Human Action Required
🛑 循环受阻 - 需要人工干预
Error Type: Access/Environment (cannot be fixed by code changes)
Error Message:
```
ECONNREFUSED 127.0.0.1:5432 - Connection refused
```
Root Cause:
PostgreSQL database is not running or not accessible.
Required Human Actions:
- Start PostgreSQL:
brew services start postgresql - Verify connection:
psql -U postgres -c "SELECT 1" - Check DATABASE_URL in .env matches running instance
After Fixing:
Run again with the same prompt, or tell me to continue.
/ralph-loop<promise>BLOCKED ENVIRONMENT</promise>
undefined错误类型: 访问/环境错误(无法通过代码变更修复)
错误信息:
```
ECONNREFUSED 127.0.0.1:5432 - Connection refused
```
根本原因:
PostgreSQL数据库未运行或无法访问。
所需人工操作:
- 启动PostgreSQL:
brew services start postgresql - 验证连接:
psql -U postgres -c "SELECT 1" - 检查.env中的DATABASE_URL是否与运行实例匹配
修复后:
再次运行并使用相同提示词,或告知我继续。
/ralph-loop<promise>BLOCKED ENVIRONMENT</promise>
undefinedCommon Blockers Checklist
常见阻碍检查表
| Error Pattern | Likely Cause | Human Fix |
|---|---|---|
| PostgreSQL not running | |
| Redis not running | |
| MongoDB not running | |
| Invalid/missing API key | Check |
| Wrong permissions/scopes | Check API key permissions |
| Missing .env file | Create from |
| Missing npm package | Run |
| Out of memory | Close other apps, increase swap |
| 错误模式 | 可能原因 | 人工修复方法 |
|---|---|---|
| PostgreSQL未运行 | |
| Redis未运行 | |
| MongoDB未运行 | |
| API密钥无效/缺失 | 检查 |
| 权限/范围错误 | 检查API密钥权限 |
| 缺失.env文件 | 从 |
| 缺失npm包 | 运行 |
| 内存不足 | 关闭其他应用、增加交换空间 |
Updated Prompt Template with Error Handling
包含错误处理的更新提示词模板
bash
/ralph-loop "bash
/ralph-loop "Task: [Feature Name]
任务: [功能名称]
Requirements
需求
- [Requirements here]
- [需求内容]
TDD Workflow
TDD工作流
- Write failing tests
- Run tests
- CLASSIFY ERROR:
- Code/logic error → fix and continue
- Access/env error → STOP and report blocker
- Implement fix
- Run tests again
- Repeat until pass or blocked
- 编写失败的测试用例
- 运行测试
- 错误分类:
- 代码/逻辑错误 → 修复并继续
- 访问/环境错误 → 停止并报告阻碍
- 实现修复
- 再次运行测试
- 重复直至通过或受阻
Completion Criteria
完成标准
- All tests passing
- Lint clean
- 所有测试通过
- Lint检查无错误
Exit Conditions
退出条件
- SUCCESS: <promise>FEATURE COMPLETE</promise>
- BLOCKED: <promise>BLOCKED ENVIRONMENT</promise> " --completion-promise "FEATURE COMPLETE" --max-iterations 25
undefined- 成功: <promise>FEATURE COMPLETE</promise>
- 受阻: <promise>BLOCKED ENVIRONMENT</promise> " --completion-promise "FEATURE COMPLETE" --max-iterations 25
undefinedMultiple Completion Promises
多完成承诺
Since Ralph only supports one , handle blockers in prompt:
--completion-promisemarkdown
undefined由于Ralph仅支持一个,在提示词中处理受阻情况:
--completion-promisemarkdown
undefinedExit Logic
退出逻辑
IF all tests pass AND lint clean:
Output: <promise>COMPLETE</promise>
IF access/environment error detected:
Output blocker report (see format above)
Output: <promise>COMPLETE</promise> # Exits loop, user sees blocker report
---如果所有测试通过且Lint检查无问题:
输出: <promise>COMPLETE</promise>
如果检测到访问/环境错误:
输出阻碍报告(参见上述格式)
输出: <promise>COMPLETE</promise> # 退出循环,用户可看到阻碍报告
---When to Use Ralph Loops
何时使用Ralph循环
Good For
适用场景
| Use Case | Why It Works |
|---|---|
| TDD feature development | Tests provide clear pass/fail feedback |
| Bug fixes | Clear reproduction → test → fix cycle |
| Refactoring | Tests ensure no regressions |
| API development | Each endpoint is independently testable |
| Greenfield projects | Can iterate without human oversight |
| Getting tests to pass | Clear success criteria |
| 使用场景 | 为何适用 |
|---|---|
| TDD功能开发 | 测试提供明确的通过/失败反馈 |
| Bug修复 | 清晰的复现→测试→修复流程 |
| 代码重构 | 测试确保无回归问题 |
| API开发 | 每个端点可独立测试 |
| 全新项目 | 无需人工干预即可迭代 |
| 确保测试通过 | 明确的成功标准 |
Not Good For
不适用场景
| Use Case | Why It Fails |
|---|---|
| Subjective design decisions | No clear "done" criteria |
| UI/UX work | Requires human judgment |
| One-shot operations | No need for iteration |
| Unclear requirements | Will loop forever |
| Production debugging | Needs human oversight |
| 使用场景 | 为何不适用 |
|---|---|
| 主观设计决策 | 无明确的“完成”标准 |
| UI/UX工作 | 需要人工判断 |
| 一次性操作 | 无需迭代 |
| 需求不明确 | 会无限循环 |
| 生产环境调试 | 需要人工监督 |
Monitoring and Control
监控与控制
Check Current Iteration
查看当前迭代次数
bash
grep '^iteration:' .claude/ralph-loop.local.mdbash
grep '^iteration:' .claude/ralph-loop.local.mdView Full State
查看完整状态
bash
head -10 .claude/ralph-loop.local.mdbash
head -10 .claude/ralph-loop.local.mdCancel Loop
取消循环
bash
/cancel-ralphbash
/cancel-ralphState File Location
状态文件位置
.claude/ralph-loop.local.md.claude/ralph-loop.local.mdIntegration with Claude Bootstrap
与Claude Bootstrap集成
Project Structure Addition
项目结构新增内容
project/
├── _project_specs/
│ └── ralph-prompts/ # Saved Ralph prompts
│ ├── feature-template.md
│ ├── bug-fix-template.md
│ └── refactor-template.md
└── .claude/
└── ralph-loop.local.md # Active loop state (gitignored)project/
├── _project_specs/
│ └── ralph-prompts/ # 保存的Ralph提示词
│ ├── feature-template.md
│ ├── bug-fix-template.md
│ └── refactor-template.md
└── .claude/
└── ralph-loop.local.md # 活跃循环状态(已加入git忽略)Gitignore Addition
Gitignore新增内容
gitignore
undefinedgitignore
undefinedRalph loop state (session-specific)
Ralph循环状态(会话特定)
.claude/ralph-loop.local.md
undefined.claude/ralph-loop.local.md
undefinedTodo Integration
待办事项集成
markdown
undefinedmarkdown
undefined[TODO-042] Add email validation
[TODO-042] 添加邮箱验证
Status: in-progress
Method: Ralph loop
状态: 进行中
方法: Ralph循环
Ralph Prompt
Ralph提示词
/ralph-loop "..." --max-iterations 20 --completion-promise "..."
/ralph-loop "..." --max-iterations 20 --completion-promise "..."
TDD Execution Log
TDD执行日志
| Iteration | Tests | Lint | Status |
|---|---|---|---|
| 1 | 0/5 pass | errors | RED |
| 2 | 2/5 pass | errors | RED |
| 3 | 5/5 pass | clean | GREEN ✓ |
| 迭代次数 | 测试结果 | Lint结果 | 状态 |
|---|---|---|---|
| 1 | 0/5通过 | 有错误 | RED |
| 2 | 2/5通过 | 有错误 | RED |
| 3 | 5/5通过 | 无错误 | GREEN ✓ |
Completion
完成情况
- Iterations used: 3/20
- Promise detected: <promise>ALL TESTS PASSING</promise>
---- 使用迭代次数: 3/20
- 检测到承诺: <promise>ALL TESTS PASSING</promise>
---Anti-Patterns
反模式
- ❌ No max iterations - Loop runs forever
- ❌ Vague completion criteria - Can't determine when done
- ❌ No TDD in prompt - No objective success metric
- ❌ Lying to exit - Outputting false promise to escape
- ❌ Manual intervention - Loop is designed for autonomy
- ❌ Skipping test verification - Tests must fail first
- ❌ 未设置最大迭代次数 - 循环会无限运行
- ❌ 模糊的完成标准 - 无法确定何时完成
- ❌ 提示词中未包含TDD - 无客观成功指标
- ❌ 伪造承诺以退出 - 输出虚假承诺来逃离循环
- ❌ 手动干预 - 循环设计为自主运行
- ❌ 跳过测试验证 - 测试必须先失败
Example: Real TDD Ralph Session
示例:真实的TDD Ralph会话
bash
/ralph-loop "bash
/ralph-loop "Task: Add email validation to signup form
任务: 为注册表单添加邮箱验证
Requirements
需求
- Email field shows error for invalid format
- Error clears when user fixes email
- Form cannot submit with invalid email
- Valid emails pass without error
- 邮箱格式无效时显示错误
- 用户修复邮箱后错误消失
- 邮箱无效时表单无法提交
- 有效邮箱可正常通过
Test Cases
测试用例
| Input | Expected |
|---|---|
| user@example.com | Valid |
| user@sub.example.com | Valid |
| notanemail | Error |
| user@ | Error |
| @example.com | Error |
| 输入 | 预期结果 |
|---|---|
| user@example.com | 有效 |
| user@sub.example.com | 有效 |
| notanemail | 错误 |
| user@ | 错误 |
| @example.com | 错误 |
TDD Workflow
TDD工作流
- Create test file: signup-validation.test.ts
- Write tests for ALL test cases above
- Run: npm test -- --grep 'email validation'
- Verify: All 5 tests FAIL (RED)
- Implement: validateEmail function
- Run: npm test -- --grep 'email validation'
- Verify: All 5 tests PASS (GREEN)
- Run: npm run lint && npm run typecheck
- If any errors, fix and re-run
- When all green, output completion
- 创建测试文件: signup-validation.test.ts
- 编写上述所有测试用例
- 运行: npm test -- --grep 'email validation'
- 验证: 全部5个测试失败(RED)
- 实现: validateEmail函数
- 运行: npm test -- --grep 'email validation'
- 验证: 全部5个测试通过(GREEN)
- 运行: npm run lint && npm run typecheck
- 如果有任何错误,修复并重新运行
- 全部通过时输出完成信息
Completion Criteria
完成标准
- 5 tests exist for email validation
- All 5 tests passing
- Lint clean
- TypeCheck passing
- 存在5个邮箱验证测试用例
- 全部5个测试通过
- Lint检查无错误
- TypeCheck通过
Exit Condition
退出条件
<promise>EMAIL VALIDATION COMPLETE</promise>
" --completion-promise "EMAIL VALIDATION COMPLETE" --max-iterations 15
---<promise>EMAIL VALIDATION COMPLETE</promise>
" --completion-promise "EMAIL VALIDATION COMPLETE" --max-iterations 15
---Checklist
检查清单
Before Starting Ralph Loop
启动Ralph循环前
- Clear completion criteria defined
- set (safety net)
--max-iterations - set
--completion-promise - TDD workflow included in prompt
- Test cases defined
- 定义了明确的完成标准
- 设置了(安全保障)
--max-iterations - 设置了
--completion-promise - 提示词中包含了TDD工作流
- 定义了测试用例
During Loop
循环运行中
- Monitor iteration count
- Check test results each iteration
- Watch for stuck patterns
- 监控迭代次数
- 每次迭代检查测试结果
- 留意停滞模式
After Completion
完成后
- Verify tests actually pass
- Run full test suite
- Check coverage threshold
- Commit changes
- 验证测试确实通过
- 运行完整测试套件
- 检查覆盖率阈值
- 提交变更