loop
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLoop
循环
A self-sustaining development loop with two modes: Researcher and Implementor.
一个具备两种模式的自维持开发循环:研究模式和实现模式。
Prerequisites
前置条件
Full permissions required. The loop runs autonomously and needs unrestricted access.
需要完整权限。该循环自主运行,需要无限制的访问权限。
Claude Code
Claude Code
bash
claude --dangerously-skip-permissionsbash
claude --dangerously-skip-permissionsCodex
Codex
The script automatically uses mode (no sandbox, no prompts).
--yolo脚本会自动使用模式(无沙箱,无提示)。
--yoloStartup Flow
启动流程
When this skill is invoked, ask the user FOUR questions using AskUserQuestion, then one text prompt:
当调用此技能时,使用AskUserQuestion向用户提出四个问题,然后是一个文本提示:
Question 1: Mode (AskUserQuestion)
问题1:模式(AskUserQuestion)
- Question: "Which mode would you like to run?"
- Options:
- - Explore, investigate, and plan. Creates specs for implementation.
Research - - Execute on specs. Write code, tests, and documentation.
Implement
- 问题:"你想要运行哪种模式?"
- 选项:
- - 探索、调研并规划。创建用于实现的规格说明。
Research - - 执行规格说明。编写代码、测试与文档。
Implement
Question 2: Git Workflow (AskUserQuestion)
问题2:Git工作流(AskUserQuestion)
- Question: "What should happen after each task?"
- Options:
- - Commit and push to current branch (default)
Push - - Commit locally, no push
Commit only - - Open PR, wait for CI (no merge)
Open PR - - Open PR, wait for CI, then auto-merge
PR and merge
- 问题:"每个任务完成后执行什么操作?"
- 选项:
- - 提交并推送到当前分支(默认)
Push - - 仅本地提交,不推送
Commit only - - 打开PR,等待CI(不合并)
Open PR - - 打开PR,等待CI,然后自动合并
PR and merge
Question 3: Context Management (AskUserQuestion)
问题3:上下文管理(AskUserQuestion)
- Question: "Should each iteration start with fresh context?"
- Options:
- - Clear context between iterations (default, recommended)
Fresh context - - Maintain conversation history across iterations
Keep context
- 问题:"每次迭代是否应从全新上下文开始?"
- 选项:
- - 迭代间清除上下文(默认,推荐)
Fresh context - - 跨迭代保留对话历史
Keep context
Question 4: Directions (AskUserQuestion - optional)
问题4:指导方向(AskUserQuestion - 可选)
- Question: "Any specific directions for this run?"
- Options (mode-aware, user can select "Other" for custom):
- - No specific directions, work autonomously
None - For Research mode:
- - Review and improve existing implementation specs
Focus on specs - - Research external libraries and frameworks
Explore dependencies
- For Implement mode:
- - Prioritize fixing build errors and warnings
Fix issues first - - Focus on implementation, skip test writing for now
Skip tests
If user selects "Other", they can provide custom directions like:
- "Focus on authentication patterns"
- "Search Apple developer docs for NSPanel"
- "Prioritize the archive feature"
- "Redo the task list with proper SwiftUI patterns"
The agent interprets directions intelligently (creating dots, modifying tasks, updating docs, changing priorities, etc.).
- 问题:"本次运行有任何特定指导方向吗?"
- 选项(与模式相关,用户可选择"Other"自定义):
- - 无特定方向,自主工作
None - 研究模式专属:
- - 评审并改进现有实现规格
Focus on specs - - 调研外部库与框架
Explore dependencies
- 实现模式专属:
- - 优先修复构建错误与警告
Fix issues first - - 专注于实现,暂时跳过测试编写
Skip tests
如果用户选择"Other",可提供如下自定义方向:
- "专注于认证模式"
- "搜索Apple开发者文档中的NSPanel"
- "优先处理归档功能"
- "使用标准SwiftUI模式重新梳理任务列表"
智能体将智能解读这些方向(创建Dots任务、修改任务、更新文档、调整优先级等)。
Question 5: Iterations (Text prompt - NOT AskUserQuestion)
问题5:迭代次数(文本提示 - 非AskUserQuestion)
After the AskUserQuestion completes, ask:
"How many iterations? Enter a number, 'inf' for infinite, or 'comp' for until complete:"
Parse the response:
- Number (e.g., "2", "5", "10") → exact iteration count
- "inf", "infinite", "-1" → infinite mode (-1)
- "comp", "complete", "0" → until complete mode (0)
Key distinction:
- Infinite / N iterations: Completion promise is IGNORED. Loop continues for re-analysis and improvement.
- Until complete: Only mode where completion promise stops the loop.
After collecting answers:
- Initialize loop state by running:
./scripts/setup-loop.sh <mode> --iterations <N> --git-workflow <workflow> [--fresh-context] [--directions "..."]- Iterations: -1=infinite, 0=until complete, N=exact count
- Workflow: commit/push/pr/pr-merge
- Directions: optional user guidance for the agent
- Build the prompt by combining mode-specific + shared content:
- Read (mode-specific sections)
<mode>-loop.md - Read (common sections)
loop-shared.md - Concatenate: mode-specific + shared
- Read
- Begin execution based on context mode:
Fresh context mode (default):
You are the orchestrator. Run this loop in the main conversation:
iteration = 0
PROMPT = contents of <mode>-loop.md + "\n\n" + contents of loop-shared.md
DIRECTIONS = user's directions (if provided)完成AskUserQuestion提问后,询问:
"需要多少次迭代?输入数字,'inf'表示无限次,或'comp'表示直到完成:"
解析响应:
- 数字(如"2"、"5"、"10")→ 精确迭代次数
- "inf"、"infinite"、"-1" → 无限模式(-1)
- "comp"、"complete"、"0" → 直到完成模式(0)
关键区别:
- 无限/N次迭代:忽略完成承诺。循环持续进行重新分析与改进。
- 直到完成:唯一会因完成承诺终止循环的模式。
收集所有回答后:
- 运行以下命令初始化循环状态:
./scripts/setup-loop.sh <mode> --iterations <N> --git-workflow <workflow> [--fresh-context] [--directions "..."]- 迭代次数:-1=无限,0=直到完成,N=精确次数
- 工作流:commit/push/pr/pr-merge
- 指导方向:智能体的可选用户指引
- 结合模式专属内容与共享内容构建提示词:
- 读取(模式专属章节)
<mode>-loop.md - 读取(通用章节)
loop-shared.md - 拼接:模式专属内容 + 通用内容
- 读取
- 根据上下文模式开始执行:
全新上下文模式(默认):
你是编排者。在主对话中运行此循环:
iteration = 0
PROMPT = contents of <mode>-loop.md + "\n\n" + contents of loop-shared.md
DIRECTIONS = user's directions (if provided)Exponential backoff for infinite mode
无限模式下的指数退避
MIN_DELAY = 5 # seconds
current_delay = MIN_DELAY
MIN_DELAY = 5 # 秒
current_delay = MIN_DELAY
If directions were provided, append them to the prompt
如果提供了方向,将其追加到提示词
if DIRECTIONS:
PROMPT = PROMPT + "\n\n## User Directions\n\n" + DIRECTIONS
LOOP:
iteration += 1
print "=== Iteration {iteration} ==="
result = Task(prompt=PROMPT, subagent_type="general-purpose")
# Check termination conditions
if iterations == 0: # "until complete" mode
if result contains "RANDROID_LOOP_COMPLETE":
print "Loop complete (promise found after {iteration} iterations)"
EXIT LOOP
elif iterations > 0: # exact N iterations mode
if iteration >= iterations:
print "Completed {iteration} iterations"
EXIT LOOP
# iterations == -1 means infinite, continues below
# Exponential backoff for infinite mode when no work done
if iterations == -1: # infinite mode
if result contains "RANDROID_LOOP_COMPLETE":
print "No work this iteration, backing off for {current_delay}s..."
sleep(current_delay)
current_delay = current_delay * 2 # No max cap
else:
# Meaningful work done, reset backoff
current_delay = MIN_DELAY
GOTO LOOP
**CRITICAL**: After each Task returns, YOU (the orchestrator) must:
1. Check the result for the completion promise
2. Check if iteration limit reached
3. If neither → spawn another Task for the next iteration
4. Do NOT stop just because one Task finished
**Keep context mode:**
Run the loop directly in the current conversation. The stop hook will intercept exit and continue looping with accumulated context.if DIRECTIONS:
PROMPT = PROMPT + "\n\n## User Directions\n\n" + DIRECTIONS
LOOP:
iteration += 1
print "=== Iteration {iteration} ==="
result = Task(prompt=PROMPT, subagent_type="general-purpose")
# 检查终止条件
if iterations == 0: # "直到完成"模式
if result contains "RANDROID_LOOP_COMPLETE":
print "Loop complete (promise found after {iteration} iterations)"
EXIT LOOP
elif iterations > 0: # 精确N次迭代模式
if iteration >= iterations:
print "Completed {iteration} iterations"
EXIT LOOP
# iterations == -1 表示无限,继续执行
# 无限模式下无工作时的指数退避
if iterations == -1: # 无限模式
if result contains "RANDROID_LOOP_COMPLETE":
print "No work this iteration, backing off for {current_delay}s..."
sleep(current_delay)
current_delay = current_delay * 2 # 无上限
else:
# 完成了有意义的工作,重置退避时间
current_delay = MIN_DELAY
GOTO LOOP
**重要提示**:每个Task返回后,你(编排者)必须:
1. 检查结果中的完成承诺
2. 检查是否达到迭代次数上限
3. 如果都不满足 → 为下一次迭代生成新的Task
4. 不要因单个Task完成就停止循环
**保留上下文模式:**
在当前对话中直接运行循环。停止钩子将拦截退出操作,并结合累积的上下文继续循环。Usage
使用方法
Interactive (Recommended)
交互式(推荐)
/loopPrompts for mode, iterations, and optional directions.
Aliases: ,
/randroid/randroid-loop/loop提示选择模式、迭代次数及可选指导方向。
别名:,
/randroid/randroid-loopDirect (Skip Questions)
直接调用(跳过提问)
- - Research mode, prompts for iterations
/loop research - - Implement mode, prompts for iterations
/loop implement - - Research mode, infinite (ignores completion)
/loop research --loop - - Research mode, stops on completion
/loop research --until-complete - - Implement mode, exactly 5 iterations
/loop implement --iterations 5 - - Open PR workflow
/loop implement --open-pr - - PR with auto-merge workflow
/loop implement --pr-and-merge - - Local commits only
/loop implement --commit-only - - Keep conversation context (no fresh start)
/loop implement --keep-context - - Combine options
/loop implement --iterations 5 --open-pr
- - 研究模式,提示输入迭代次数
/loop research - - 实现模式,提示输入迭代次数
/loop implement - - 研究模式,无限次(忽略完成承诺)
/loop research --loop - - 研究模式,完成后停止
/loop research --until-complete - - 实现模式,精确5次迭代
/loop implement --iterations 5 - - 打开PR工作流
/loop implement --open-pr - - PR并自动合并工作流
/loop implement --pr-and-merge - - 仅本地提交
/loop implement --commit-only - - 保留对话上下文(不重新开始)
/loop implement --keep-context - - 组合选项
/loop implement --iterations 5 --open-pr
With Directions
带指导方向
You can provide guidance for the agent. When prompted for directions:
- Select a preset option (mode-specific), or
- Select "Other" and type custom directions like:
- "Focus on authentication patterns"
- "Prioritize the archive feature, skip tests for now"
Directions can include:
- Topics to research or questions to answer
- Priorities for which tasks to work on
- Specific implementation guidance
- Requests to redo or improve previous work
- Scope changes (add/remove/modify tasks)
可为智能体提供指引。当被问及方向时:
- 选择预设选项(模式专属),或
- 选择"Other"并输入自定义方向,例如:
- "专注于认证模式"
- "优先处理归档功能,暂时跳过测试"
方向可包含:
- 需要调研的主题或要解答的问题
- 任务优先级
- 特定实现指引
- 重做或改进之前工作的请求
- 范围变更(添加/移除/修改任务)
Codex (External Script)
Codex(外部脚本)
bash
undefinedbash
undefinedFrom terminal (outside Codex)
从终端(Codex外部)运行
./scripts/randroid-loop.sh
./scripts/randroid-loop.sh
Interactive prompts for mode, iterations, and git workflow
交互式提示选择模式、迭代次数及Git工作流
Note: Wrapper always uses fresh context (each iteration is a new codex exec)
注意:包装器始终使用全新上下文(每次迭代都是新的Codex执行)
Direct invocation:
直接调用:
./scripts/randroid-loop.sh research -1 # infinite
./scripts/randroid-loop.sh research 0 # until complete
./scripts/randroid-loop.sh implement 5 # exactly 5 iterations
./scripts/randroid-loop.sh implement 5 pr # 5 iterations, open PR
./scripts/randroid-loop.sh implement 0 pr-merge # until complete, PR + merge
undefined./scripts/randroid-loop.sh research -1 # 无限次
./scripts/randroid-loop.sh research 0 # 直到完成
./scripts/randroid-loop.sh implement 5 # 精确5次迭代
./scripts/randroid-loop.sh implement 5 pr # 5次迭代,打开PR
./scripts/randroid-loop.sh implement 0 pr-merge # 直到完成,PR并合并
undefinedModes
模式说明
Research Mode
研究模式
The researcher explores, investigates, and plans. It:
- Creates prefixed dots to track its own exploration
research: - Creates prefixed dots as deliverables for the implementor
implement: - Does NOT write production code
- Outputs findings, decisions, and clear implementation specs
研究模式用于探索、调研与规划。它会:
- 创建前缀为的Dots任务跟踪自身探索过程
research: - 创建前缀为的Dots任务作为实现模式的交付物
implement: - 不编写生产代码
- 输出调研结果、决策及清晰的实现规格
Implementor Mode
实现模式
The implementor executes. It:
- Pulls from ready dots
implement: - Writes code, tests, and documentation
- Creates new dots if scope expands
implement: - Creates dots if blocked by unknowns (for next research cycle)
research:
实现模式用于执行开发。它会:
- 从已就绪的前缀Dots任务中获取工作
implement: - 编写代码、测试与文档
- 若范围扩展则创建新的前缀Dots任务
implement: - 若因未知问题受阻则创建前缀Dots任务(用于下一轮研究循环)
research:
Loop Mechanics
循环机制
Fresh Context Each Iteration
每次迭代使用全新上下文
Each loop iteration starts with fresh conversational context. Only the filesystem persists:
- Modified files
- Git history and commits
- Dots system state
- Research/implementation artifacts
This prevents context bloat and allows the agent to approach each iteration with clarity.
每次循环迭代都从全新对话上下文开始。仅文件系统状态会保留:
- 修改后的文件
- Git历史与提交
- Dots系统状态
- 研究/实现工件
这可避免上下文膨胀,让智能体每次迭代都能清晰地开展工作。
What Persists
保留的内容
- All file changes from previous iterations
- Git commits and history
- task state
.dots/ - Any written documentation or specs
- 之前迭代的所有文件变更
- Git提交与历史
- 任务状态
.dots/ - 已编写的文档或规格
What Resets
重置的内容
- Conversation history
- In-memory state
- Token usage (fresh budget each iteration)
- 对话历史
- 内存状态
- Token使用量(每次迭代重置配额)
Loop Termination
循环终止
Output when:
<promise>RANDROID_LOOP_COMPLETE</promise>- No more ready tasks for your mode
- All work is committed and pushed
The loop also stops when limit is reached.
--iterations N当满足以下条件时输出:
<promise>RANDROID_LOOP_COMPLETE</promise>- 当前模式下无就绪任务
- 所有工作已提交并推送
当达到次数上限时,循环也会停止。
--iterations NArchitecture
架构
loop/
├── SKILL.md # This file
├── research-loop.md # Research mode prompt
├── implement-loop.md # Implementor mode prompt
├── loop-shared.md # Shared sections (git, dots, termination)
├── LOOPING_DESIGN.md # Technical design doc
├── hooks/
│ └── stop-hook.sh # Claude Code stop hook
├── scripts/
│ ├── setup-loop.sh # Initialize loop state
│ └── randroid-loop.sh # Codex external wrapper
└── state/
└── .gitignore # Excludes local state filesloop/
├── SKILL.md # 本文档
├── research-loop.md # 研究模式提示词
├── implement-loop.md # 实现模式提示词
├── loop-shared.md # 共享章节(Git、Dots、终止)
├── LOOPING_DESIGN.md # 技术设计文档
├── hooks/
│ └── stop-hook.sh # Claude Code停止钩子
├── scripts/
│ ├── setup-loop.sh # 初始化循环状态
│ └── randroid-loop.sh # Codex外部包装器
└── state/
└── .gitignore # 排除本地状态文件