sugar
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePhased Software Engineering Execution
分阶段软件工程执行流程
Task
任务
$ARGUMENTS
$ARGUMENTS
Reference
参考
Subagent execution follows the Ralph pattern. Each phase workspace is a self-contained Ralph environment: (agent instructions), (story state machine), (learning persistence). Subagents are autonomous — they read their workspace instructions and execute independently.
CLAUDE.mdprd.jsonprogress.txtThe Sugar library () is the source of truth for all execution logic. Skills delegate to CLI commands for workspace management, story state, consensus, and pattern propagation. Do not embed procedural bash scripts or Python one-liners — use Sugar CLI instead.
src/lib/sugar子代理(subagent)的执行遵循**Ralph**模式。每个阶段的工作区都是一个独立的Ralph环境:(代理指令)、(故事状态机)、(学习持久化文件)。子代理具备自主性——它们读取工作区指令并独立执行。
CLAUDE.mdprd.jsonprogress.txtSugar库()是所有执行逻辑的唯一可信来源。技能需委托给 CLI命令进行工作区管理、故事状态维护、一致性校验和模式传播。请勿嵌入过程式bash脚本或Python单行代码——请使用Sugar CLI替代。
src/lib/sugarPrompt reinforcement
提示强化
Use prompt repetition at every decision boundary: state the task, provide context, give the instruction, restate context briefly, repeat the instruction. Apply at skill level (restate before each phase), subagent level (each workspace CLAUDE.md repeats the task), and per-story (restate acceptance criteria before implementing).
$ARGUMENTS在每个决策节点使用提示重复:陈述任务、提供上下文、给出指令、简要重述上下文、重复指令。在技能层面(每个阶段前重述)、子代理层面(每个工作区的CLAUDE.md重复任务)以及每个故事层面(实现前重述验收标准)应用此规则。
$ARGUMENTSCore behavior
核心行为
Execute in strict phases. Never move to the next phase without explicit user approval.
Before every phase, restate: "The original task is: $ARGUMENTS. This phase's goal is: [phase goal]."
按照严格的阶段执行。未获得用户明确批准,绝不进入下一阶段。
每个阶段开始前,重述:"原始任务为:$ARGUMENTS。本阶段目标为:[阶段目标]。"
Phase 1 — Planning
阶段1 — 规划
Goal
目标
Analyze the task and produce a complete execution plan. Do not implement any code.
Restate: The original task is . This phase produces and only.
$ARGUMENTSplan.mdtodo.md分析任务并生成完整的执行计划。请勿实现任何代码。
重述:原始任务为。本阶段仅生成和文件。
$ARGUMENTSplan.mdtodo.mdActions
操作
Use the skill approach: analyze the task, ask clarifying questions if ambiguous, then produce structured requirements.
/prdCreate at the repo root containing:
plan.md- objective, scope, assumptions, constraints, risks
- dependency map — which parts depend on other parts
- architecture / refactor / testing strategy as relevant
- execution phases with explicit dependency annotations
- blockers
Create at the repo root containing:
todo.md- small, actionable, idempotent tasks grouped by phase
- checkbox progress tracking ()
- [ ] - dependency annotations per task
- completion criteria per phase
使用技能方法:分析任务,若存在歧义则提出澄清问题,然后生成结构化需求。
/prd在仓库根目录创建文件,包含:
plan.md- 目标、范围、假设、约束、风险
- 依赖关系图——各部分之间的依赖关系
- 相关的架构/重构/测试策略
- 带有明确依赖标注的执行阶段
- 阻塞点
在仓库根目录创建文件,包含:
todo.md- 按阶段分组的小型、可执行、幂等任务
- 复选框进度跟踪()
- [ ] - 每个任务的依赖标注
- 每个阶段的完成标准
Rules
规则
- Do not implement anything or create branches
- Stop after Phase 1 and wait for user approval
- 请勿实现任何内容或创建分支
- 完成阶段1后停止,等待用户批准
Phase 2 — Workspace and branch setup
阶段2 — 工作区与分支设置
Goal
目标
Create an isolated Ralph workspace for each execution phase.
Restate: The original task is . This phase creates one git worktree per phase, each pre-loaded with the Ralph agent structure.
$ARGUMENTS为每个执行阶段创建独立的Ralph工作区。
重述:原始任务为。本阶段为每个阶段创建一个git工作树,每个工作树预加载Ralph代理结构。
$ARGUMENTSPreconditions
前置条件
Only start after explicit user approval.
仅在获得用户明确批准后启动。
Actions
操作
Use the Sugar CLI to create workspaces:
bash
undefined使用Sugar CLI创建工作区:
bash
undefinedCreate workspace for each phase
为每个阶段创建工作区
sugar workspace create <phase-name>
sugar workspace create <phase-name>
List created workspaces
列出已创建的工作区
sugar workspace list
Branch naming: `phase-a-<scope>`, `phase-b-<scope>`, etc.sugar workspace list
分支命名规则:`phase-a-<scope>`、`phase-b-<scope>`等。Rules
规则
- One worktree per phase, one branch per phase
- Do not start implementation unless user approves Phase 3
- Document setup problems in
plan.md
- 每个阶段对应一个工作树和一个分支
- 除非用户批准阶段3,否则请勿开始实现
- 在中记录设置过程中出现的问题
plan.md
Phase 3 — Dependency analysis, PRD generation, and parallel implementation
阶段3 — 依赖分析、PRD生成与并行实现
Preconditions
前置条件
Only start after explicit user approval.
Restate: The original task is . This phase analyzes dependencies, generates Ralph workspaces with prd.json and CLAUDE.md per phase, then launches all independent phases as parallel subagents.
$ARGUMENTSSub-phases: 3a → 3b → 3c.
仅在获得用户明确批准后启动。
重述:原始任务为。本阶段分析依赖关系,为每个阶段生成带有prd.json和CLAUDE.md的Ralph工作区,然后将所有独立阶段作为并行子代理启动。
$ARGUMENTS子阶段:3a → 3b → 3c。
Phase 3a — Dependency analysis
阶段3a — 依赖分析
Read thoroughly. For each phase determine:
plan.md- Produces: artifacts, files, APIs, types, state changes
- Consumes: what it needs from other phases
- Hard dependencies: must complete before this starts
- Soft dependencies: helpful but not blocking
- Independence: zero overlap with other phases
Build the dependency graph. Identify parallel groups, sequential chains, and the critical path.
仔细阅读。为每个阶段确定:
plan.md- 产出:工件、文件、API、类型、状态变更
- 消耗:需要从其他阶段获取的内容
- 强依赖:必须在本阶段开始前完成的任务
- 弱依赖:有帮助但不阻塞的任务
- 独立性:与其他阶段无重叠
构建依赖关系图。识别并行组、顺序链和关键路径。
Phase 3b — Generate execution.md, prd.json, and CLAUDE.md per workspace
阶段3b — 为每个工作区生成execution.md、prd.json和CLAUDE.md
The Sugar library generates all workspace files. Use the class or CLI commands:
Orchestratorbash
undefinedSugar库负责生成所有工作区文件。使用类或CLI命令:
Orchestratorbash
undefinedInitialize config if not present
若配置不存在则初始化
sugar config init
sugar config init
The orchestrator generates: execution.md, prd.json, CLAUDE.md, VERIFY.md, ralph-loop.sh per workspace
编排器会生成:execution.md、prd.json、CLAUDE.md、VERIFY.md、ralph-loop.sh(每个工作区一份)
For each workspace, the library generates:
- **`prd.json`** — Ralph-format user stories with consensus state machine
- **`CLAUDE.md`** — Agent instructions with iron laws, quality protocol, red flags
- **`VERIFY.md`** — Verifier agent instructions with vote format
- **`ralph-loop.sh`** — Iteration engine that spawns fresh agents per story
- **`execution.md`** at repo root — dependency graph, parallel groups, model strategy
**Story rules:** completable in one pass, ordered by dependency (schema → backend → UI), verifiable criteria, always include "Typecheck passes".
对于每个工作区,库会生成:
- **`prd.json`** — 带有一致性状态机的Ralph格式用户故事
- **`CLAUDE.md`** — 包含铁律、质量协议、警示信号的代理指令
- **`VERIFY.md`** — 带有投票格式的验证器代理指令
- **`ralph-loop.sh`** — 为每个故事生成新代理实例的迭代引擎
- **`execution.md`**(仓库根目录)— 依赖关系图、并行组、模型策略
**故事规则**:单次迭代可完成,按依赖顺序排列( schema → 后端 → UI),具备可验证标准,始终包含"类型检查通过"项。Rules
规则
- Every workspace must have: ,
prd.json,progress.txt,CLAUDE.md,ralph-loop.shVERIFY.md - Do not proceed to 3c until all workspaces are fully set up
- Validate each :
prd.jsonsugar validate <workspace>/prd.json
- 每个工作区必须包含:、
prd.json、progress.txt、CLAUDE.md、ralph-loop.shVERIFY.md - 所有工作区完全设置完成后,才可进入3c阶段
- 验证每个:
prd.jsonsugar validate <workspace>/prd.json
Phase 3c — Parallel execution via ralph-loop.sh
阶段3c — 通过ralph-loop.sh进行并行执行
Goal
目标
Launch the Ralph iteration loop for each phase in parallel.
为每个阶段启动Ralph迭代循环并并行运行。
How iteration works
迭代工作原理
ralph-loop.sh (the loop — runs in bash)
├── Iteration 1: claude < CLAUDE.md → implements US-001 → exits
├── Iteration 2: claude < CLAUDE.md → implements US-002 → exits
├── Iteration 3: claude < CLAUDE.md → implements US-003 → outputs PHASE_COMPLETE
└── Loop exits successfullyEach iteration is a fresh agent instance with clean context. Memory persists via:
- — which stories are done (
prd.json)status: "passed"/"pending"/"rejected" - — learnings and codebase patterns
progress.txt - git history — all committed code
ralph-loop.sh(循环脚本——在bash中运行)
├── 迭代1:claude < CLAUDE.md → 实现US-001 → 退出
├── 迭代2:claude < CLAUDE.md → 实现US-002 → 退出
├── 迭代3:claude < CLAUDE.md → 实现US-003 → 输出PHASE_COMPLETE
└── 循环成功退出每次迭代都是一个全新的代理实例,上下文干净。记忆通过以下方式持久化:
- — 标记哪些故事已完成(
prd.json)status: "passed"/"pending"/"rejected" - — 学习成果和代码库模式
progress.txt - git历史 — 所有已提交的代码
Execution
执行
Follow group ordering. Launch ralph loops per group:
execution.mdbash
undefined遵循中的组顺序。按组启动ralph循环:
execution.mdbash
undefinedLaunch all independent phases in parallel
并行启动所有独立阶段
/tmp/<repo>-phases/phase-a/ralph-loop.sh 20 sonnet &
/tmp/<repo>-phases/phase-b/ralph-loop.sh 20 sonnet &
wait
/tmp/<repo>-phases/phase-a/ralph-loop.sh 20 sonnet &
/tmp/<repo>-phases/phase-b/ralph-loop.sh 20 sonnet &
wait
Propagate patterns between groups
在组之间传播模式
sugar propagate-patterns --base /tmp/<repo>-phases
sugar propagate-patterns --base /tmp/<repo>-phases
Launch next group
启动下一组
/tmp/<repo>-phases/phase-c/ralph-loop.sh 20 sonnet &
wait
The `ralph-loop.sh` uses Sugar CLI for state management:
- `sugar pick-story` — get next story
- `sugar story-update` — update story status in prd.json
- `sugar snapshot` — create git snapshot tag before each attempt/tmp/<repo>-phases/phase-c/ralph-loop.sh 20 sonnet &
wait
`ralph-loop.sh`使用Sugar CLI进行状态管理:
- `sugar pick-story` — 获取下一个故事
- `sugar story-update` — 更新prd.json中的故事状态
- `sugar snapshot` — 每次尝试前创建git快照标签Model selection per phase
各阶段模型选择
- Sonnet (default): Well-scoped implementation tasks
- Haiku: Mechanical tasks — config changes, boilerplate
- Opus: Complex architectural decisions, ambiguous requirements
Auto-escalates to Opus on 2+ consecutive failures.
- Sonnet(默认):范围明确的实现任务
- Haiku:机械性任务——配置变更、模板代码
- Opus:复杂架构决策、模糊需求
连续失败2次及以上时自动升级为Opus。
Completion tracking
完成跟踪
- Phase complete when exits 0
ralph-loop.sh - After each group: to extract and inject patterns
sugar propagate-patterns - Monitor progress:
sugar status-all /tmp/<repo>-phases
- 当以0状态退出时,阶段完成
ralph-loop.sh - 每组完成后:使用提取并注入模式
sugar propagate-patterns - 监控进度:
sugar status-all /tmp/<repo>-phases
Rules
规则
- Never launch a dependent phase before prerequisites are confirmed complete
- Propagate codebase patterns between groups
- One story per commit, all commits must pass quality checks
- 确认前置阶段完成前,绝不启动依赖阶段
- 在组之间传播代码库模式
- 每个故事对应一次提交,所有提交必须通过质量检查
Phase 4 — Merge
阶段4 — 合并
Goal
目标
Safely integrate all completed phase branches.
Restate: The original task is . All phases complete. Merge in dependency order.
$ARGUMENTS安全整合所有已完成阶段的分支。
重述:原始任务为。所有阶段已完成。按依赖顺序合并。
$ARGUMENTSPreconditions
前置条件
Only start after explicit user approval.
仅在获得用户明确批准后启动。
Actions
操作
bash
undefinedbash
undefinedView workspace status first
先查看工作区状态
sugar status-all /tmp/<repo>-phases
Create `merge_order.md` at repo root with:
- merge order aligned with dependency graph (foundations first)
- rationale for ordering
- expected conflict areas
- conflict resolution notes
- validation steps after each merge
**Automatic merge:**
- Merge in documented order
- Resolve conflicts using best engineering judgment
- Validate after each merge: run quality checks
- Update `merge_order.md` with actual conflict notessugar status-all /tmp/<repo>-phases
在仓库根目录创建`merge_order.md`文件,包含:
- 与依赖关系图一致的合并顺序(基础部分优先)
- 顺序合理性说明
- 预期冲突区域
- 冲突解决说明
- 每次合并后的验证步骤
**自动合并**:
- 按文档记录的顺序合并
- 使用最佳工程判断解决冲突
- 每次合并后验证:运行质量检查
- 在`merge_order.md`中更新实际冲突记录Post-merge validation
合并后验证
Phase 4 is not complete until the final merged result passes all checks.
只有当最终合并结果通过所有检查后,阶段4才完成。
Cleanup
清理
bash
sugar workspace cleanupbash
sugar workspace cleanupIron Laws
铁律
Three inviolable rules enforced in every workspace:
- ONE STORY per iteration — no "while I'm here" additions
- NEVER COMMIT BROKEN code — every commit must pass all quality checks
- READ PROGRESS.TXT FIRST — check codebase patterns before writing
每个工作区都必须遵守的三条不可违反规则:
- 每次迭代仅处理一个故事 — 禁止添加“顺手做的”内容
- 绝不提交损坏的代码 — 每次提交必须通过所有质量检查
- 先阅读PROGRESS.TXT — 编写代码前先查看代码库模式
Red Flags — If You Catch Yourself Thinking:
警示信号——如果你有以下想法:
| Thought | Reality |
|---|---|
| "I'll just implement two quick stories in one iteration" | ONE story per iteration. The loop handles iteration. No exceptions. |
| "The tests mostly pass, I'll commit and fix later" | ALL commits must pass quality checks. Broken commits poison every future iteration. |
| "This dependency isn't really needed, I'll skip it" | The dependency graph exists for a reason. Never start dependent work before prerequisites complete. |
| "I know what changed, I don't need to read progress.txt" | Progress.txt IS your memory. You have NO context without it. Read it FIRST. |
| "This is a trivial change, I don't need to run checks" | Every commit gets checked. No exceptions. The one you skip is the one that breaks everything. |
| "I'll refactor this while I'm here" | Stay in scope. Implement the story. Nothing more. |
| 想法 | 实际要求 |
|---|---|
| "我要在一次迭代中快速实现两个故事" | 每次迭代仅处理一个故事。循环会处理迭代流程。无例外。 |
| "测试大部分通过,我先提交之后再修复" | 所有提交必须通过质量检查。损坏的提交会影响后续所有迭代。 |
| "这个依赖其实不需要,我跳过它" | 依赖关系图存在是有原因的。前置任务完成前,绝不启动依赖工作。 |
| "我知道哪些内容变更了,不需要读progress.txt" | Progress.txt是你的记忆来源。没有它你就没有上下文。必须先阅读。 |
| "这是个小改动,不需要运行检查" | 每次提交都要检查。无例外。你跳过的那次检查往往就是导致崩溃的原因。 |
| "我顺便重构一下这里" | 保持在范围内。只实现故事内容。不做额外操作。 |
How to interpret user requests
如何解读用户请求
| User says | Start from |
|---|---|
| Planning only / no qualifier | Phase 1 |
| Planning is approved | Phase 2 |
| Setup is done | Phase 3 (3a → 3b → 3c) |
| PRDs exist, ready to implement | Phase 3c |
| All branches done, wants merge | Phase 4 |
| Testing only | Phase 1 (testing strategy), then normal flow |
| 用户表述 | 起始阶段 |
|---|---|
| 仅规划 / 无其他限定 | 阶段1 |
| 规划已批准 | 阶段2 |
| 已完成设置 | 阶段3(3a → 3b → 3c) |
| PRD已存在,准备实现 | 阶段3c |
| 所有分支已完成,需要合并 | 阶段4 |
| 仅测试 | 阶段1(制定测试策略),然后按正常流程执行 |
Execution rules
执行规则
Source of truth
可信来源
- Before Phase 3c:
todo.md - During Phase 3c: each workspace's
prd.json - After each phase completes: sync back to
todo.md
- 阶段3c之前:
todo.md - 阶段3c期间:每个工作区的
prd.json - 每个阶段完成后:同步更新至
todo.md
Commits
提交规范
- One per story:
feat: [Story ID] - [Story Title] - Must pass quality checks
- Never bundle unrelated changes
- 每个故事对应一次提交:
feat: [故事ID] - [故事标题] - 必须通过质量检查
- 绝不捆绑无关变更
General
通用规则
- Never skip phases or continue without approval
- Keep all tracking files current
- Document assumptions and blockers explicitly
- Propagate codebase patterns between groups
- 绝不跳过阶段或未获批准就继续执行
- 保持所有跟踪文件更新
- 明确记录假设和阻塞点
- 在组之间传播代码库模式
Managed files
管理文件
| File | Location | Created in |
|---|---|---|
| repo root | Phase 1 |
| repo root | Phase 1 |
| repo root | Phase 3b |
| each worktree | Phase 3b |
| each worktree | Phase 2 |
| each worktree | Phase 3b |
| each worktree | Phase 3b |
| each worktree | Phase 3b |
| repo root | Phase 3c (between groups) |
| repo root | Phase 4 |
The first deliverable is always Phase 1 planning only, unless the user explicitly states that a later phase is already approved.
Restate: Given the task — start with Phase 1. Produce and . Stop and wait for approval.
$ARGUMENTSplan.mdtodo.md| 文件 | 位置 | 创建阶段 |
|---|---|---|
| 仓库根目录 | 阶段1 |
| 仓库根目录 | 阶段1 |
| 仓库根目录 | 阶段3b |
| 每个工作树 | 阶段3b |
| 每个工作树 | 阶段2 |
| 每个工作树 | 阶段3b |
| 每个工作树 | 阶段3b |
| 每个工作树 | 阶段3b |
| 仓库根目录 | 阶段3c(组之间) |
| 仓库根目录 | 阶段4 |
除非用户明确说明已批准后续阶段,否则首个交付成果始终仅为阶段1的规划内容。
重述:给定任务 — 从阶段1开始。生成和。停止并等待批准。
$ARGUMENTSplan.mdtodo.md