ralph
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseralph - Self-Referential Completion Loop
ralph - 自引用完成循环
When to use this skill
何时使用该Skill
- Long-running implementation tasks that tend to stop early
- Tasks that need autonomous multi-turn iteration without manual intervention
- Workflows where the agent must self-correct and refine output across turns
- Sessions where exact completion signaling is required before stopping
- 容易提前终止的长期实现任务
- 无需人工干预、需要自主多轮迭代的任务
- Agent必须在多轮过程中自我修正并优化输出的工作流
- 需要明确完成信号后再停止的会话
Core Concept
核心概念
The loop happens across agent turns, controlled by an hook.
AfterAgent- You run ONCE:
/ralph "Your task description" --completion-promise "DONE" - Agent works: Performs actions (modifies files, runs tests, writes code)
- Hook intercepts: When the agent finishes its turn, the hook intercepts the exit
AfterAgent - Loop continuation: Hook evaluates state (max iterations, promise) and starts a new turn with the original prompt, clearing the previous turn's context
- Repeat: Continues autonomously until completion or user interruption
循环在Agent的多轮交互中进行,由钩子控制。
AfterAgent- 仅需运行一次:
/ralph "你的任务描述" --completion-promise "DONE" - Agent执行任务:执行操作(修改文件、运行测试、编写代码)
- 钩子拦截:当Agent完成当前轮次后,钩子会拦截退出操作
AfterAgent - 循环继续:钩子评估当前状态(最大迭代次数、完成标识),并使用原始提示词启动新的轮次,同时清除上一轮的上下文
- 重复执行:自主持续循环,直到任务完成或用户中断
Why this works
为什么这种方式有效
- Stable Context & No Compaction: Prompt never changes between iterations; previous conversational context is cleared. The agent relies on current file state, not stale chat history.
- Persistent State: The agent's work persists in files and git history across iterations.
- Autonomous Improvement: Each iteration sees the current codebase state and improves on past work.
- Ghost Protection: If you interrupt the loop and start a new task, the hook detects the prompt mismatch and silently cleans up.
- 稳定上下文且无压缩:迭代过程中提示词保持不变;之前的对话上下文会被清除。Agent依赖当前文件状态,而非过时的聊天历史。
- 状态持久化:Agent的工作成果会在多轮迭代中保留在文件和Git历史中。
- 自主优化:每一轮迭代都会基于当前代码库状态,对之前的工作进行改进。
- 干扰防护:如果您中断循环并启动新任务,钩子会检测到提示词不匹配,并自动清理相关状态。
1. Core Command Pattern
1. 核心命令格式
text
/ralph "<task description>" [--completion-promise=TEXT] [--max-iterations=N]Defaults:
- Completion promise:
DONE - Max iterations:
100
text
/ralph "<任务描述>" [--completion-promise=TEXT] [--max-iterations=N]默认值:
- 完成标识:
DONE - 最大迭代次数:
100
2. How the Loop Behaves
2. 循环运行机制
- Starts with your task prompt.
- On each turn end, the hook checks whether the assistant output contains:
AfterAgent
xml
<promise>DONE</promise>- If not found, hook starts a new agent turn with the same original prompt (context cleared).
- Stops only when:
- Completion promise is detected in output, or
- Max iterations is reached, or
- You run
/ralph:cancel
- 从您的任务提示词开始执行。
- 在每轮结束时,钩子会检查助手的输出中是否包含:
AfterAgent
xml
<promise>DONE</promise>- 如果未找到该标识,钩子会使用相同的原始提示词启动新的Agent轮次(上下文已清除)。
- 仅在以下情况停止:
- 输出中检测到完成标识,或
- 达到最大迭代次数,或
- 您执行命令
/ralph:cancel
3. Practical Usage
3. 实际使用场景
Standard run
标准运行
text
/ralph "Build a Python CLI task manager with full test coverage"text
/ralph "构建一个具备完整测试覆盖率的Python CLI任务管理器"With completion promise
自定义完成标识
text
/ralph "Build a REST API for todos. When all CRUD endpoints work and tests pass with >80% coverage, output TASK_COMPLETE" --completion-promise="TASK_COMPLETE"text
/ralph "构建一个待办事项REST API。当所有CRUD端点正常工作且测试覆盖率超过80%时,输出TASK_COMPLETE" --completion-promise="TASK_COMPLETE"Bounded iteration run
限制迭代次数运行
text
/ralph "Attempt to refactor the authentication module" --max-iterations=20text
/ralph "尝试重构认证模块" --max-iterations=20TDD workflow with self-correction
包含自我修正的TDD工作流
text
/ralph "Implement feature X by following TDD:
1. Write failing tests for the feature.
2. Implement the code to make the tests pass.
3. Run the test suite.
4. If any tests fail, analyze the errors and debug.
5. Refactor for clarity and efficiency.
6. Repeat until all tests are green.
7. When complete, output <promise>TESTS_PASSED</promise>" --completion-promise="TESTS_PASSED"text
/ralph "遵循TDD流程实现功能X:
1. 为该功能编写失败的测试用例。
2. 实现代码使测试通过。
3. 运行测试套件。
4. 如果有测试失败,分析错误并调试。
5. 重构代码以提升清晰度和效率。
6. 重复上述步骤直到所有测试通过。
7. 完成后输出 <promise>TESTS_PASSED</promise>" --completion-promise="TESTS_PASSED"Cancel active loop
取消活跃循环
text
/ralph:canceltext
/ralph:cancelView help
查看帮助
text
/ralph:helptext
/ralph:help4. Prompt Writing Best Practices
4. 提示词编写最佳实践
1. Clear Completion Criteria
1. 明确完成标准
Provide a verifiable definition of "done." The is crucial.
--completion-promiseGood:
text
/ralph "Build a REST API for todos. When all CRUD endpoints are working and all tests pass with >80% coverage, you're complete." --completion-promise="TASK_COMPLETE"提供可验证的“完成”定义。参数至关重要。
--completion-promise示例(良好):
text
/ralph "构建一个待办事项REST API。当所有CRUD端点正常工作且所有测试通过、覆盖率超过80%时,任务完成。" --completion-promise="TASK_COMPLETE"2. Use Safety Hatches
2. 使用安全机制
Always use as a safety net to prevent infinite loops.
--max-iterationstext
/ralph "Attempt to refactor the authentication module" --max-iterations=20始终使用作为安全保障,防止无限循环。
--max-iterationstext
/ralph "尝试重构认证模块" --max-iterations=203. Encourage Self-Correction
3. 鼓励自我修正
Structure the prompt to guide the agent through work → verify → debug cycles.
设计提示词以引导Agent遵循“工作→验证→调试”的循环流程。
5. Launch Safely
5. 安全启动
Always run in sandbox mode for safety. Enabling YOLO mode () prevents constant tool execution prompts during the loop:
-ybash
gemini -s -y为了安全起见,始终在沙箱模式下运行。启用YOLO模式()可避免循环过程中频繁出现工具执行提示:
-ybash
gemini -s -y6. Installation (Gemini CLI)
6. 安装(Gemini CLI)
bash
gemini extensions install https://github.com/gemini-cli-extensions/ralph --auto-updateRequired in :
~/.gemini/settings.jsonjson
{
"hooksConfig": { "enabled": true },
"context": {
"includeDirectories": ["~/.gemini/extensions/ralph"]
}
}bash
gemini extensions install https://github.com/gemini-cli-extensions/ralph --auto-update~/.gemini/settings.jsonjson
{
"hooksConfig": { "enabled": true },
"context": {
"includeDirectories": ["~/.gemini/extensions/ralph"]
}
}6. Codex에서 사용 (권장 보정)
6. 在Codex中使用(推荐修正方案)
ralph따라서 Codex에서 를 쓸 때는 아래 보정 스크립트를 설치해 사용하는 것을 권장합니다.
ralphbash
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh이 스크립트가 수행하는 것:
- 의
~/.codex/config.toml에developer_instructions재시작 계약 정보를 기록ralph - 생성 (
~/.codex/prompts/ralph.md로 빠른 실행)/prompts:ralph - 옵션으로 적용 전 미리보기
--dry-run
text
Usage:
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh --dry-run⚠️ 정확성 유의:
- Codex에서 완전 자동 루프를 강제하는 네이티브 훅은 현재 제한적입니다.
- 위 설정은 동작 계약을 고정시키고, 다음 작업을 반복할 때 수동 실수(
ralph누락, promise 누락, max 반복 초과)를 줄여줍니다./prompts:ralph
ralph在Gemini中基于AfterAgent钩子实现自动循环,但Codex目前不支持原生的结束钩子。
因此,在Codex中使用ralph时,建议安装以下修正脚本:
bash
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh该脚本会执行以下操作:
- 在的
~/.codex/config.toml中记录ralph的重启协议信息developer_instructions - 创建文件(可通过
~/.codex/prompts/ralph.md快速执行)/prompts:ralph - 支持选项,可在应用前预览效果
--dry-run
text
使用方法:
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh
bash <your-agent-skills>/ralph/scripts/setup-codex-hook.sh --dry-run⚠️ 注意准确性:
- Codex目前对强制实现完全自动循环的原生钩子支持有限。
- 上述配置会固化ralph的运行协议,减少后续重复任务时的人为失误(如遗漏、遗漏完成标识、超出最大迭代次数等)。
/prompts:ralph
플랫폼별 적용 상태 (현재 지원 기준)
各平台适配状态(当前支持标准)
| 플랫폼 | 현재 지원 방식 | 핵심 조건 |
|---|---|---|
| Gemini-CLI | 네이티브 | |
| Claude Code | 네이티브(권장) | 스킬/오케스트레이션 적재 후 |
| OpenCode | 네이티브(동일 경로) | |
| Codex | 보정 모드 | |
현재 스킬만- Gemini-CLI/Claude Code/OpenCode: 가능
- Codex: 로 보정한 뒤 운영 가능
setup-codex-hook.sh
| 平台 | 当前支持方式 | 核心条件 |
|---|---|---|
| Gemini-CLI | 原生支持 | 安装 |
| Claude Code | 原生支持(推荐) | 加载Skill/编排后使用 |
| OpenCode | 原生支持(路径一致) | 注册 |
| Codex | 修正模式 | 执行 |
仅通过当前Skill是否可用:
- Gemini-CLI/Claude Code/OpenCode:是
- Codex:执行修正后可用
setup-codex-hook.sh
Quick Reference
快速参考
| Action | Command |
|---|---|
| Start loop | |
| Custom promise | |
| Iteration cap | |
| Cancel | |
| Help | |
| 操作 | 命令 |
|---|---|
| 启动循环 | |
| 自定义完成标识 | |
| 限制迭代次数 | |
| 取消循环 | |
| 查看帮助 | |