loop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Loop

循环

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-permissions
bash
claude --dangerously-skip-permissions

Codex

Codex

The script automatically uses
--yolo
mode (no sandbox, no prompts).
脚本会自动使用
--yolo
模式(无沙箱,无提示)。

Startup 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:
    1. Research
      - Explore, investigate, and plan. Creates specs for implementation.
    2. Implement
      - Execute on specs. Write code, tests, and documentation.
  • 问题:"你想要运行哪种模式?"
  • 选项
    1. Research
      - 探索、调研并规划。创建用于实现的规格说明。
    2. Implement
      - 执行规格说明。编写代码、测试与文档。

Question 2: Git Workflow (AskUserQuestion)

问题2:Git工作流(AskUserQuestion)

  • Question: "What should happen after each task?"
  • Options:
    • Push
      - Commit and push to current branch (default)
    • Commit only
      - Commit locally, no push
    • Open PR
      - Open PR, wait for CI (no merge)
    • PR and merge
      - Open PR, wait for CI, then auto-merge
  • 问题:"每个任务完成后执行什么操作?"
  • 选项
    • Push
      - 提交并推送到当前分支(默认)
    • Commit only
      - 仅本地提交,不推送
    • Open PR
      - 打开PR,等待CI(不合并)
    • PR and merge
      - 打开PR,等待CI,然后自动合并

Question 3: Context Management (AskUserQuestion)

问题3:上下文管理(AskUserQuestion)

  • Question: "Should each iteration start with fresh context?"
  • Options:
    • Fresh context
      - Clear context between iterations (default, recommended)
    • Keep context
      - Maintain conversation history across iterations
  • 问题:"每次迭代是否应从全新上下文开始?"
  • 选项
    • 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):
    • None
      - No specific directions, work autonomously
    • For Research mode:
      • Focus on specs
        - Review and improve existing implementation specs
      • Explore dependencies
        - Research external libraries and frameworks
    • For Implement mode:
      • Fix issues first
        - Prioritize fixing build errors and warnings
      • Skip tests
        - Focus on implementation, skip test writing for now
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:
  1. 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
  2. Build the prompt by combining mode-specific + shared content:
    • Read
      <mode>-loop.md
      (mode-specific sections)
    • Read
      loop-shared.md
      (common sections)
    • Concatenate: mode-specific + shared
  3. 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次迭代:忽略完成承诺。循环持续进行重新分析与改进。
  • 直到完成:唯一会因完成承诺终止循环的模式。
收集所有回答后:
  1. 运行以下命令初始化循环状态:
    ./scripts/setup-loop.sh <mode> --iterations <N> --git-workflow <workflow> [--fresh-context] [--directions "..."]
    • 迭代次数:-1=无限,0=直到完成,N=精确次数
    • 工作流:commit/push/pr/pr-merge
    • 指导方向:智能体的可选用户指引
  2. 结合模式专属内容与共享内容构建提示词:
    • 读取
      <mode>-loop.md
      (模式专属章节)
    • 读取
      loop-shared.md
      (通用章节)
    • 拼接:模式专属内容 + 通用内容
  3. 根据上下文模式开始执行:
全新上下文模式(默认): 你是编排者。在主对话中运行此循环:
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)

交互式(推荐)

/loop
Prompts for mode, iterations, and optional directions.
Aliases:
/randroid
,
/randroid-loop
/loop
提示选择模式、迭代次数及可选指导方向。
别名:
/randroid
,
/randroid-loop

Direct (Skip Questions)

直接调用(跳过提问)

  • /loop research
    - Research mode, prompts for iterations
  • /loop implement
    - Implement mode, prompts for iterations
  • /loop research --loop
    - Research mode, infinite (ignores completion)
  • /loop research --until-complete
    - Research mode, stops on completion
  • /loop implement --iterations 5
    - Implement mode, exactly 5 iterations
  • /loop implement --open-pr
    - Open PR workflow
  • /loop implement --pr-and-merge
    - PR with auto-merge workflow
  • /loop implement --commit-only
    - Local commits only
  • /loop implement --keep-context
    - Keep conversation context (no fresh start)
  • /loop implement --iterations 5 --open-pr
    - Combine options
  • /loop research
    - 研究模式,提示输入迭代次数
  • /loop implement
    - 实现模式,提示输入迭代次数
  • /loop research --loop
    - 研究模式,无限次(忽略完成承诺)
  • /loop research --until-complete
    - 研究模式,完成后停止
  • /loop implement --iterations 5
    - 实现模式,精确5次迭代
  • /loop implement --open-pr
    - 打开PR工作流
  • /loop implement --pr-and-merge
    - PR并自动合并工作流
  • /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
undefined
bash
undefined

From 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并合并
undefined

Modes

模式说明

Research Mode

研究模式

The researcher explores, investigates, and plans. It:
  • Creates
    research:
    prefixed dots to track its own exploration
  • Creates
    implement:
    prefixed dots as deliverables for the implementor
  • Does NOT write production code
  • Outputs findings, decisions, and clear implementation specs
研究模式用于探索、调研与规划。它会:
  • 创建前缀为
    research:
    的Dots任务跟踪自身探索过程
  • 创建前缀为
    implement:
    的Dots任务作为实现模式的交付物
  • 不编写生产代码
  • 输出调研结果、决策及清晰的实现规格

Implementor Mode

实现模式

The implementor executes. It:
  • Pulls from ready
    implement:
    dots
  • Writes code, tests, and documentation
  • Creates new
    implement:
    dots if scope expands
  • Creates
    research:
    dots if blocked by unknowns (for next research cycle)
实现模式用于执行开发。它会:
  • 从已就绪的
    implement:
    前缀Dots任务中获取工作
  • 编写代码、测试与文档
  • 若范围扩展则创建新的
    implement:
    前缀Dots任务
  • 若因未知问题受阻则创建
    research:
    前缀Dots任务(用于下一轮研究循环)

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
  • .dots/
    task state
  • Any written documentation or specs
  • 之前迭代的所有文件变更
  • Git提交与历史
  • .dots/
    任务状态
  • 已编写的文档或规格

What Resets

重置的内容

  • Conversation history
  • In-memory state
  • Token usage (fresh budget each iteration)
  • 对话历史
  • 内存状态
  • Token使用量(每次迭代重置配额)

Loop Termination

循环终止

Output
<promise>RANDROID_LOOP_COMPLETE</promise>
when:
  • No more ready tasks for your mode
  • All work is committed and pushed
The loop also stops when
--iterations N
limit is reached.
当满足以下条件时输出
<promise>RANDROID_LOOP_COMPLETE</promise>
  • 当前模式下无就绪任务
  • 所有工作已提交并推送
当达到
--iterations N
次数上限时,循环也会停止。

Architecture

架构

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 files
loop/
├── 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        # 排除本地状态文件