ralph-loop
Ralph Wiggum 迭代开发循环。三阶段工作流(需求→规划→构建),每阶段有 code review + 测试 gate。 触发词:ralph loop、迭代开发、interview me、plan system、build system。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Ralph Wiggum 迭代开发循环。三阶段工作流(需求→规划→构建),每阶段有 code review + 测试 gate。 触发词:ralph loop、迭代开发、interview me、plan system、build system。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | ralph-loop |
| description | Ralph Wiggum 迭代开发循环。三阶段工作流(需求→规划→构建),每阶段有 code review + 测试 gate。 触发词:ralph loop、迭代开发、interview me、plan system、build system。 |
基于 Geoffrey Huntley 的 Ralph Wiggum 技术的自主迭代开发。
核心: 每个阶段有强制 code review + 测试 gate,不通过不进下一阶段。
| 短语 | 动作 |
|---|---|
| "Ralph loop over X" | 问走哪个阶段 |
| "Interview me about X" | Phase 1: 需求收集 |
| "Plan system X" | Phase 2: 规划循环 |
| "Build system X" | Phase 3: 构建循环 |
Phase 1: REQUIREMENTS ──── 人机对话 → specs/*.md
Gate: 用户确认所有 spec
Phase 2: PLANNING ──────── 差距分析 → IMPLEMENTATION_PLAN.md
Gate: Plan review + 验证(命令存在、路径有效)
Phase 3: BUILDING ──────── 迭代实现 → test → Codex review → commit
Gate: 测试通过 + Codex cross-review(完成时)
| 当前状态 | 阶段 | 动作 |
|---|---|---|
没有 specs/ 或为空 | Phase 1 | 跑需求访谈 |
有 specs/*.md,没有 IMPLEMENTATION_PLAN.md | Phase 2 | 跑规划循环 |
| 有 spec + plan | Phase 3 | 跑构建循环 |
| Plan 显示全部完成 | Done | 汇报 |
目标: JTBD → Topics → specs/*.md
specs/<topic>.md,包含验收标准 + 边界情况Phase 1 specs 确认后,立即初始化 .ralph/ 目录:
收集配置信息(用 AskUserQuestion):
claude / codex / opencode / goose(默认 claude)npm test && npm run typecheck && npm run lint0(无限)用 cp 复制模板文件到项目的 .ralph/,然后在副本上编辑(不要读模板再重写!):
mkdir -p .ralph/state
cp /path/to/skill/templates/loop.sh .ralph/loop.sh
cp /path/to/skill/templates/PROMPT_plan.md .ralph/PROMPT_plan.md
cp /path/to/skill/templates/PROMPT_build.md .ralph/PROMPT_build.md
chmod +x .ralph/loop.sh
模板源路径: 此 skill 基础目录下的 templates/
在复制后的文件上替换占位符:
.ralph/loop.sh 中替换 {{CLI}}、{{MODE}}、{{MAX_ITERS}}、{{BACKPRESSURE_CMD}}.ralph/PROMPT_plan.md 中替换 [PROJECT_GOAL] 和源码路径.ralph/PROMPT_build.md 中替换源码路径如果项目根目录没有 AGENTS.md,从 templates 复制一份并让用户适配
目标: 生成 IMPLEMENTATION_PLAN.md — 不实现任何东西。
执行方式:Claude Code 直接在 Bash 中运行 loop.sh:
cd /path/to/project && .ralph/loop.sh plan
loop.sh 会用 PROMPT_plan.md 反复调用 AI CLI,直到 IMPLEMENTATION_PLAN.md 中出现 STATUS: PLANNING_COMPLETE。
loop.sh plan 完成后,Claude Code 自动读取并展示 IMPLEMENTATION_PLAN.md 给用户 review:
IMPLEMENTATION_PLAN.md 存在,任务有优先级npm test 等)Review 通过后,Claude Code 立即启动 Phase 3(不要让用户手动运行)。
目标: 迭代实现任务,保持 context 新鲜。
执行方式:Claude Code 直接在 Bash 中运行 loop.sh:
cd /path/to/project && .ralph/loop.sh build
# 或限制迭代次数:
cd /path/to/project && .ralph/loop.sh build 50
loop.sh 会用 PROMPT_build.md 反复调用 AI CLI,每次迭代自动执行:
1. 读 IMPLEMENTATION_PLAN.md → 挑合理粒度的任务
2. 调研代码库(不要假设没实现!)
3. 实现任务
4. 跑背压:测试 + typecheck + lint
5. Code review:对照 spec 验收标准
6. 更新 IMPLEMENTATION_PLAN.md
7. git commit + git push(有 remote 时)
8. AI CLI 退出 → loop.sh 启动下一轮(全新 context)
如果背压失败,loop.sh 把错误写入 .ralph/state/last-feedback.txt,下一轮 AI 会自动收到并尝试修复。
如果 AI 判断自己卡住了,会创建 RALPH-BLOCKED.md,loop.sh 检测到后停止,等人工介入。
所有任务完成后,AI 在 IMPLEMENTATION_PLAN.md 中写入 STATUS: COMPLETE。loop.sh 检测到后会自动运行 cross-review(优先独立 reviewer,fallback 到 self-review):
last-feedback.txt,STATUS: COMPLETE 被撤回,下一轮继续修复RALPH_MAX_REVIEW 可配)→ loop.sh 写入 checkpoint 文件并 exit 2,外层 agent 判断是否继续| 指标 | 目标 |
|---|---|
| 行覆盖率 | ≥ 80% |
| 分支覆盖率 | ≥ 70% |
| 新代码覆盖率 | ≥ 90% |
Phase 2 → Phase 3 自动过渡流程:
loop.sh plan 完成(检测到 STATUS: PLANNING_COMPLETE)IMPLEMENTATION_PLAN.md 展示给用户loop.sh buildPhase 3 退出码处理:
loop.sh build 退出:
exit 0 → 完成(LGTM 或 PLANNING_COMPLETE)
exit 1 → 失败(max iterations 或 blocked)
exit 2 → review checkpoint,需要 agent 判断
exit 130 → 用户 Ctrl+C
Exit 2 处理流程(review 软上限):
.ralph/state/review-checkpoint.mdloop.sh build(round 重置为 0)STATUS: COMPLETE,删除 checkpoint,告知用户完成三层,按顺序叠加:
测试、typecheck、lint、build。确定性、快速。
每次迭代后验证:
所有任务完成、STATUS: COMPLETE 写入后:
# Plan phase
grep -Fq "STATUS: PLANNING_COMPLETE" IMPLEMENTATION_PLAN.md
# Build phase
grep -Fq "STATUS: COMPLETE" IMPLEMENTATION_PLAN.md
project/
├── .ralph/
│ ├── loop.sh # 主循环脚本(cp 自模板,Claude Code 直接运行)
│ ├── PROMPT_plan.md # 规划阶段 prompt(cp 自模板后编辑)
│ ├── PROMPT_build.md # 构建阶段 prompt(cp 自模板后编辑)
│ ├── ralph.log # 运行日志
│ └── state/
│ ├── iteration.txt # 当前迭代次数(支持断点续跑)
│ ├── last-feedback.txt # 上次失败的反馈 / review 反馈
│ ├── review-round.txt # 连续 review 轮次(LGTM 或 builder 写新代码后重置)
│ └── review-checkpoint.md # review 软上限暂停时的 checkpoint(exit 2 时生成)
├── IMPLEMENTATION_PLAN.md # 带优先级的任务列表(生成的)
├── AGENTS.md # build/test/lint 命令
├── RALPH-BLOCKED.md # (可选) AI 卡住时自动创建,需人工介入
└── specs/ # 需求 spec
├── topic-a.md
└── topic-b.md
用递增编号的 guardrails(Geoffrey 的模式):
99999. Important: 在文档中记录 why。
999999. Important: 单一数据源,不搞迁移。
9999999. 成功 build 后打 git tag。
99999999. 保持 IMPLEMENTATION_PLAN.md 更新。
999999999. 完整实现 — 不留 placeholder 或 stub。
mkdir -p myproject/specs && cd myproject && git init
Phase 1: Interview → 写 specs/ → 用户确认
↓
过渡: cp 模板到 .ralph/(配置 CLI、背压命令)
↓
Phase 2: Claude Code 运行 .ralph/loop.sh plan → 展示 plan 给用户 review
↓
Phase 3: 用户确认后 Claude Code 自动运行 .ralph/loop.sh build → Codex 守门 → 完成
.ralph/loop.sh plan # 只跑规划
.ralph/loop.sh build # 只跑构建
.ralph/loop.sh both # 先规划再构建
.ralph/loop.sh build 50 # 最多 50 次迭代
tail -f .ralph/ralph.log # 实时查看日志
cat RALPH-BLOCKED.md # 查看卡住原因(如果有)
| 问题 | 解法 |
|---|---|
| 同一任务被重复实现 | 重新跑规划循环 |
| 原地打转 | 加更具体的测试作为背压 |
| Context 膨胀 | 确保迭代粒度合理 |
| 测试抓不到问题 | 加集成测试,不要只写单元测试 |
| Cross-review 反复不通过 | 15 轮后 exit 2 自动暂停,外层 agent 判断是否继续 |
| Exit 2 checkpoint | 读 .ralph/state/review-checkpoint.md,分析问题价值,决定继续或完成 |
Based on work by:
Capture a multi-step workflow into a timestamped pipeline memory after trial-and-error sessions. The core output is: (1) the final working commands saved as executable scripts (not bare shell commands), and (2) a structured markdown document separating the clean reproducible pipeline from the detours and pitfalls. Timestamped snapshots live in pipeline_memory/; mature pipelines can be promoted to PIPELINE.md and auto-loaded. Fully environment-agnostic — works for any project, any toolset, any domain. Use when the user finishes a multi-step task, says "保存工作流记忆", "save pipeline memory", "记录一下当前进展", or "/save-pipeline-memory". Takes an optional folder path.
Run Claude Code commands (including /insights, /doctor, custom prompts) via system crontab in non-interactive mode. Use when: (1) setting up daily/weekly automated Claude Code tasks, (2) scheduling reports or analysis via cron, (3) running Claude Code with third-party API backends (DeepSeek, Qwen, etc.) in headless environments, (4) "set up a daily report", "automate this in cron", "schedule insights". Covers: cron PATH setup, third-party API env vars for non-interactive mode, nvm/node auto-discovery, and wechat-reminder integration for notification delivery.
Use when the user wants to *learn* or *understand* a technical concept (an algorithm, a math derivation, an ML architecture, a systems internal) rather than just get a one-shot answer — triggers include "explain X", "teach me X", "help me understand X", or being stuck on a concept while reading a paper or code. Probe the user's level with a few questions FIRST, then teach interactively through a runnable Jupyter notebook with LaTeX derivations and small experiments.
Claudeception is a continuous learning system that extracts reusable knowledge from work sessions. Triggers: (1) /claudeception command to review session learnings, (2) "save this as a skill" or "extract a skill from this", (3) "what did we learn?", (4) After any task involving non-obvious debugging, workarounds, or trial-and-error discovery. Creates new Claude Code skills when valuable, reusable knowledge is identified.
Record a debugging session's findings into a timestamped markdown file under debug_experience/. Captures problem, root cause, solution, and key learnings in a structured, reusable format. Use when: you've just resolved a non-obvious bug, found an undocumented edge case, encountered an issue that took multiple attempts to fix, or when you say things like "保存调试经验", "save debug experience", "记录这次调试", "/save-debug-experience". Takes an optional folder path as argument.
MCP Notion工具使用指南,包含常见问题解决方案和最佳实践。使用当: (1) 访问Notion数据库view URL出现"URL type view not currently supported"错误, (2) 需要获取数据库schema和表结构信息, (3) 查询数据库中的条目内容, (4) 创建页面时MULTI_SELECT字段值不存在导致失败, (5) 需要更新数据库schema添加新选项, (6) 开发需要集成Notion数据的自动化工作流, (7) query_data_sources/query-database-view返回Business Plan要求错误, (8) 需要在无Business Plan的情况下枚举数据库所有条目。