iterative-planner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIterative Planner
迭代式规划器
Core Principle: Context Window = RAM. Filesystem = Disk.
Write to disk immediately. The context window will rot. The files won't.
{plan-dir}plans/plan_YYYY-MM-DD_XXXXXXXX/plans/.current_planplans/FINDINGS.mdplans/DECISIONS.md核心原则:上下文窗口 = 内存(RAM)。文件系统 = 磁盘(Disk)。
立即写入磁盘。上下文窗口会失效,但文件不会。
{plan-dir}plans/plan_YYYY-MM-DD_XXXXXXXX/plans/.current_planplans/FINDINGS.mdplans/DECISIONS.mdState Machine
状态机
mermaid
stateDiagram-v2
[*] --> EXPLORE
EXPLORE --> PLAN : enough context
PLAN --> EXPLORE : need more context
PLAN --> PLAN : user rejects / revise
PLAN --> EXECUTE : user approves
EXECUTE --> REFLECT : phase ends/failed/surprise/leash
REFLECT --> CLOSE : all criteria met
REFLECT --> RE_PLAN : failed / better approach
REFLECT --> EXPLORE : need more context
RE_PLAN --> PLAN : new approach ready
CLOSE --> [*]| State | Purpose | Allowed Actions |
|---|---|---|
| EXPLORE | Gather context | Read-only on project. Write only to |
| PLAN | Design approach | Write plan.md. NO code changes. |
| EXECUTE | Implement step-by-step | Edit files, run commands, write code. |
| REFLECT | Evaluate results | Read outputs, run tests. Update decisions.md. |
| RE-PLAN | Revise direction | Log pivot in decisions.md. Do NOT write plan.md yet. |
| CLOSE | Finalize | Write summary.md. Audit decision anchors. Merge findings/decisions to consolidated files. |
mermaid
stateDiagram-v2
[*] --> EXPLORE
EXPLORE --> PLAN : enough context
PLAN --> EXPLORE : need more context
PLAN --> PLAN : user rejects / revise
PLAN --> EXECUTE : user approves
EXECUTE --> REFLECT : phase ends/failed/surprise/leash
REFLECT --> CLOSE : all criteria met
REFLECT --> RE_PLAN : failed / better approach
REFLECT --> EXPLORE : need more context
RE_PLAN --> PLAN : new approach ready
CLOSE --> [*]| 状态 | 目标 | 允许的操作 |
|---|---|---|
| EXPLORE(探索) | 收集上下文 | 仅可读项目文件,仅可写入 |
| PLAN(规划) | 设计实现方案 | 写入plan.md,禁止修改代码 |
| EXECUTE(执行) | 分步实现 | 编辑文件、运行命令、编写代码 |
| REFLECT(反思) | 评估结果 | 读取输出、运行测试、更新decisions.md |
| RE-PLAN(重新规划) | 调整方向 | 在decisions.md中记录转向,暂不写入plan.md |
| CLOSE(关闭) | 最终收尾 | 写入summary.md,审核决策锚点,将发现/决策合并到统一文件中 |
Transitions
状态转换
| From → To | Trigger |
|---|---|
| EXPLORE → PLAN | Sufficient context. ≥3 indexed findings in |
| PLAN → EXPLORE | Can't state problem, can't list files, or insufficient findings. |
| PLAN → PLAN | User rejects plan. Revise and re-present. |
| PLAN → EXECUTE | User explicitly approves. |
| EXECUTE → REFLECT | Execution phase ends (all steps done, failure, surprise, or leash hit). |
| REFLECT → CLOSE | All criteria verified PASS in |
| REFLECT → RE-PLAN | Failure or better approach found. |
| REFLECT → EXPLORE | Need more context before re-planning. |
| RE-PLAN → PLAN | New approach formulated. Decision logged. |
Every transition → log in . RE-PLAN transitions → also log in (what failed, what learned, why new direction).
At CLOSE → audit decision anchors (). Merge per-plan findings/decisions to and .
state.mddecisions.mdreferences/decision-anchoring.mdplans/FINDINGS.mdplans/DECISIONS.md| 起始→目标 | 触发条件 |
|---|---|
| 探索→规划 | 上下文足够, |
| 规划→探索 | 无法明确问题、无法列出相关文件,或发现内容不足 |
| 规划→规划 | 用户拒绝当前规划,需要修订后重新提交 |
| 规划→执行 | 用户明确批准规划 |
| 执行→反思 | 执行阶段结束(所有步骤完成、执行失败、出现意外或触发自主限制) |
| 反思→关闭 | |
| 反思→重新规划 | 执行失败或发现更优方案 |
| 反思→探索 | 重新规划前需要更多上下文 |
| 重新规划→规划 | 新方案已确定,决策已记录 |
每次状态转换→记录到中。重新规划的转换→同时记录到(包括失败原因、经验总结、转向新方案的理由)。
关闭阶段→审核决策锚点()。将当前计划的发现/决策合并到和中。
state.mddecisions.mdreferences/decision-anchoring.mdplans/FINDINGS.mdplans/DECISIONS.mdMandatory Re-reads (CRITICAL)
强制重读规则(至关重要)
These files are active working memory. Re-read during the conversation, not just at start.
| When | Read | Why |
|---|---|---|
| Before any EXECUTE step | | Confirm step, manifest, fix attempts, progress sync |
| Before writing a fix | | Don't repeat failed approaches. Check 3-strike. |
Before modifying | Referenced | Understand why before changing |
| Before PLAN or RE-PLAN | | Ground plan in known facts |
| Before any REFLECT | | Compare against written criteria, not vibes |
| Every 10 tool calls | | Reorient. Right step? Scope crept? |
>50 messages: re-read + before every response. Files are truth, not memory.
state.mdplan.md以下文件是活跃的工作内存。在对话过程中需要反复阅读,而不仅仅是开始时读一次。
| 时机 | 读取文件 | 原因 |
|---|---|---|
| 任何执行步骤之前 | | 确认当前步骤、变更记录、修复尝试、进度同步 |
| 编写修复代码之前 | | 避免重复已失败的方案,检查三次失败规则 |
修改带有 | 对应的 | 修改前先理解原有决策的原因 |
| 规划或重新规划之前 | | 基于已知事实制定规划 |
| 任何反思阶段之前 | | 对照书面标准进行评估,而非凭感觉 |
| 每调用10次工具之后 | | 重新定位方向,确认是否在正确的步骤上,是否出现范围蔓延 |
对话消息超过50条:每次回复前都要重读 + 。文件是事实依据,而非记忆。
state.mdplan.mdBootstrapping
引导启动
bash
node <skill-path>/scripts/bootstrap.mjs "goal" # Create new plan (backward-compatible)
node <skill-path>/scripts/bootstrap.mjs new "goal" # Create new plan
node <skill-path>/scripts/bootstrap.mjs new --force "goal" # Close active plan, create new one
node <skill-path>/scripts/bootstrap.mjs resume # Re-entry summary for new sessions
node <skill-path>/scripts/bootstrap.mjs status # One-line state summary
node <skill-path>/scripts/bootstrap.mjs close # Close plan (preserves directory)
node <skill-path>/scripts/bootstrap.mjs list # Show all plan directoriesnewresumeclose--forcenew.gitignoreplans/closestate.md.current_plansummary.mdclose{plan-dir}state.mdplan.mddecisions.mdfindings.mdprogress.mdverification.mdfindings.mdbash
node <skill-path>/scripts/bootstrap.mjs "goal" # 创建新计划(向后兼容)
node <skill-path>/scripts/bootstrap.mjs new "goal" # 创建新计划
node <skill-path>/scripts/bootstrap.mjs new --force "goal" # 关闭活跃计划,创建新计划
node <skill-path>/scripts/bootstrap.mjs resume # 为新会话生成重入摘要
node <skill-path>/scripts/bootstrap.mjs status # 生成单行状态摘要
node <skill-path>/scripts/bootstrap.mjs close # 关闭计划(保留计划目录)
node <skill-path>/scripts/bootstrap.mjs list # 显示所有计划目录如果存在活跃计划,命令会拒绝执行——请使用、或参数。
命令会确保包含——防止执行步骤提交时将计划文件纳入版本控制。
命令会将当前计划的发现/决策合并到统一文件中,更新,并删除指针。在运行命令之前,Agent需要完成协议规定的关闭阶段操作(写入、审核决策锚点)。
引导启动完成后→读取中的所有文件(, , , , , ),然后再执行其他操作。随后进入探索阶段。用户提供的上下文→首先写入。
newresumeclose--forcenew.gitignoreplans/closestate.md.current_planclosesummary.md{plan-dir}state.mdplan.mddecisions.mdfindings.mdprogress.mdverification.mdfindings.mdFilesystem Structure
文件系统结构
plans/
├── .current_plan # → active plan directory name
├── FINDINGS.md # Consolidated findings across all plans (merged on close)
├── DECISIONS.md # Consolidated decisions across all plans (merged on close)
└── plan_2026-02-14_a3f1b2c9/ # {plan-dir}
├── state.md # Current state + transition log
├── plan.md # Living plan (rewritten each iteration)
├── decisions.md # Append-only decision/pivot log
├── findings.md # Summary + index of findings
├── findings/ # Detailed finding files (subagents write here)
├── progress.md # Done vs remaining
├── verification.md # Verification results per REFLECT cycle
├── checkpoints/ # Snapshots before risky changes
└── summary.md # Written at CLOSETemplates:
references/file-formats.mdplans/
├── .current_plan # → 指向活跃计划目录的名称
├── FINDINGS.md # 所有计划的统一发现记录(关闭计划时合并)
├── DECISIONS.md # 所有计划的统一决策记录(关闭计划时合并)
└── plan_2026-02-14_a3f1b2c9/ # {plan-dir}
├── state.md # 当前状态 + 转换日志
├── plan.md # 动态更新的计划文档(每次迭代都会重写)
├── decisions.md # 仅追加的决策/转向日志
├── findings.md # 发现内容摘要 + 索引
├── findings/ # 详细的发现文件(子Agent写入此处)
├── progress.md # 已完成 vs 待完成任务
├── verification.md # 每次反思阶段的验证结果
├── checkpoints/ # 风险变更前的快照
└── summary.md # 关闭阶段写入模板文件:
references/file-formats.mdFile Lifecycle Matrix
文件生命周期矩阵
R = read only | W = update (implicit read + write) | R+W = distinct read and write operations | — = do not touch (wrong state if you are).
Read-before-write rule: Always read a plan file before writing/overwriting it — even on the first update after bootstrap. Claude Code's Write tool will reject writes to files you haven't read in the current session. This applies to every W and R+W cell below.
| File | EXPLORE | PLAN | EXECUTE | REFLECT | RE-PLAN | CLOSE |
|---|---|---|---|---|---|---|
| state.md | W | W | R+W | W | W | W |
| plan.md | — | W | R+W | R | R | R |
| decisions.md | — | R+W | R | R+W | R+W | R |
| findings.md | W | R | — | R | R+W | R |
| findings/* | W | R | — | R | R+W | R |
| progress.md | — | W | R+W | R+W | W | R |
| verification.md | — | W | W | W | R | R |
| checkpoints/* | — | — | W | R | R | — |
| summary.md | — | — | — | — | — | W |
| plans/FINDINGS.md | R | R | — | — | R | W(merge) |
| plans/DECISIONS.md | R | R | — | — | R | W(merge) |
R = 仅可读 | W = 可更新(隐含读取+写入) | R+W = 独立的读取和写入操作 | — = 禁止操作(当前状态下不应触碰)。
写前读规则:在写入/覆盖计划文件之前,必须先读取该文件——即使是引导启动后的第一次更新也不例外。Claude Code的写入工具会拒绝写入当前会话中未读取过的文件。此规则适用于下表中所有W和R+W的单元格。
| 文件 | 探索 | 规划 | 执行 | 反思 | 重新规划 | 关闭 |
|---|---|---|---|---|---|---|
| state.md | W | W | R+W | W | W | W |
| plan.md | — | W | R+W | R | R | R |
| decisions.md | — | R+W | R | R+W | R+W | R |
| findings.md | W | R | — | R | R+W | R |
| findings/* | W | R | — | R | R+W | R |
| progress.md | — | W | R+W | R+W | W | R |
| verification.md | — | W | W | W | R | R |
| checkpoints/* | — | — | W | R | R | — |
| summary.md | — | — | — | — | — | W |
| plans/FINDINGS.md | R | R | — | — | R | W(合并) |
| plans/DECISIONS.md | R | R | — | — | R | W(合并) |
Per-State Rules
各状态规则
EXPLORE
探索阶段
- Read ,
state.mdandplans/FINDINGS.mdat start of EXPLORE for cross-plan context.plans/DECISIONS.md - Read code, grep, glob, search. One focused question at a time.
- Flush to +
findings.mdafter every 2 reads. Read the file first before each write.findings/ - Include file paths + code path traces (e.g. →
auth.rb:23→SessionStore#find).redis_store.rb:get - DO NOT skip EXPLORE even if you think you know the answer.
- Minimum depth: ≥3 indexed findings in before transitioning to PLAN. Findings must cover: (1) problem scope, (2) affected files, (3) existing patterns or constraints. Fewer than 3 → keep exploring.
findings.md - Use Task subagents to parallelize research. All subagent output → files. Never rely on context-only results. Main agent updates
{plan-dir}/findings/index after subagents write — subagents don't touch the index. Naming:findings.md(kebab-case, descriptive — e.g.findings/{topic-slug}.md,auth-system.md).test-coverage.md - Use "think hard" / "ultrathink" for complex analysis.
- REFLECT → EXPLORE loops: append to existing findings, don't overwrite. Mark corrections with .
[CORRECTED iter-N]
- 探索阶段开始时,读取,
state.md和plans/FINDINGS.md以获取跨计划上下文。plans/DECISIONS.md - 读取代码、使用grep、glob、搜索工具。一次聚焦一个问题。
- 每进行2次读取操作后,将内容写入+
findings.md。每次写入前必须先读取文件。findings/ - 包含文件路径 + 代码调用链(例如→
auth.rb:23→SessionStore#find)。redis_store.rb:get - 即使你认为自己知道答案,也不要跳过探索阶段。
- 最低要求:中至少有3条索引化的发现,才能转换到规划阶段。发现内容必须涵盖:(1) 问题范围,(2) 受影响的文件,(3) 现有模式或约束条件。不足3条→继续探索。
findings.md - 使用任务子Agent并行开展研究。所有子Agent的输出→写入目录下的文件。切勿仅依赖上下文结果。主Agent在子Agent写入后更新
{plan-dir}/findings/的索引——子Agent不得修改索引。命名规则:findings.md(短横线命名法,描述性名称——例如findings/{topic-slug}.md,auth-system.md)。test-coverage.md - 对于复杂分析,使用“深度思考”/“极致思考”模式。
- 反思→探索的循环:追加到现有发现内容,不要覆盖。用标记修正内容。
[CORRECTED iter-N]
PLAN
规划阶段
- Gate check: read ,
state.md,plan.md,findings.md,findings/*,decisions.md,progress.md,verification.md,plans/FINDINGS.mdbefore writing anything. If not read → read now. No exceptions. Ifplans/DECISIONS.mdhas <3 indexed findings → go back to EXPLORE.findings.md - Problem Statement first — before designing steps, write in : (1) what behavior is expected, (2) invariants — what must always be true, (3) edge cases at boundaries. Can't state the problem clearly → go back to EXPLORE.
plan.md - Write : problem statement, steps, failure modes, risks, success criteria, verification strategy, complexity budget.
plan.md - Verification Strategy — for each success criterion, define: what test/check to run, what command to execute, what result means "pass". Write to plan.md section. Plans with no testable criteria → write "N/A — manual review only" (proves you checked). See
Verification Strategyfor template.references/file-formats.md - Failure Mode Analysis — for each external dependency or integration point in the plan, answer: what if slow? returns garbage? is down? What's the blast radius? Write to plan.md section. No dependencies → write "None identified" (proves you checked).
Failure Modes - Write : log chosen approach + why (mandatory even for first plan). Trade-off rule — phrase every decision as "X at the cost of Y". Never recommend without stating what it costs.
decisions.md - Read then write with initial template (criteria table populated from success criteria, methods from verification strategy, results pending).
verification.md - Read then write +
state.md.progress.md - List every file to modify/create. Can't list them → go back to EXPLORE.
- Only recommended approach in plan. Alternatives → .
decisions.md - Wait for explicit user approval.
- 准入检查:写入任何内容之前,必须读取,
state.md,plan.md,findings.md,findings/*,decisions.md,progress.md,verification.md,plans/FINDINGS.md。如果未读取→立即读取。无例外。如果plans/DECISIONS.md中的索引化发现不足3条→返回探索阶段。findings.md - 先写问题陈述——在设计步骤之前,在中写入:(1) 预期行为,(2) 不变量——必须始终保持为真的条件,(3) 边界处的边缘情况。如果无法清晰陈述问题→返回探索阶段。
plan.md - 写入:问题陈述、执行步骤、失败模式、风险、成功标准、验证策略、复杂度预算。
plan.md - 验证策略——针对每个成功标准,定义:要运行的测试/检查、要执行的命令、什么结果代表“通过”。写入的“验证策略”部分。如果计划没有可测试的标准→写入“N/A — 仅需人工审核”(证明你已检查过)。模板参见
plan.md。references/file-formats.md - 失败模式分析——针对计划中的每个外部依赖或集成点,回答:如果依赖变慢?返回无效数据?服务宕机?影响范围有多大?写入的“失败模式”部分。如果没有依赖→写入“未识别到依赖”(证明你已检查过)。
plan.md - 写入:记录选定的方案及其原因(即使是第一个计划也必须记录)。权衡规则——每个决策都要表述为“选择X,代价是Y”。绝不推荐不说明代价的方案。
decisions.md - 先读取再写入,使用初始模板(从成功标准填充验证标准表格,从验证策略填充方法,结果列为待填充)。
verification.md - 先读取再写入+
state.md。progress.md - 列出所有需要修改/创建的文件。如果无法列出→返回探索阶段。
- 计划中仅包含推荐的方案。替代方案→写入。
decisions.md - 等待用户明确批准。
EXECUTE
执行阶段
- Pre-Step Checklist in : reset all boxes
state.md, then check each[ ]as completed before starting the step. This is the file-based enforcement of Mandatory Re-reads.[x] - Iteration 1, first EXECUTE → create (nuclear fallback). "Git State" = commit hash BEFORE changes (the restore point).
checkpoints/cp-000-iter1.md - One step at a time. Post-Step Gate after each (see below).
- Checkpoint before risky changes (3+ files, shared modules, destructive ops). Name: (e.g.
cp-NNN-iterN.md). Increment NNN globally across iterations.cp-001-iter2.md - Commit after each successful step: .
[iter-N/step-M] description - If something breaks → STOP. 2 fix attempts max (Autonomy Leash). Each must follow Revert-First.
- Irreversible operations (DB migrations, external API calls, service config, non-tracked file deletion): mark step in
[IRREVERSIBLE]during PLAN. Full procedure:plan.md.references/code-hygiene.md - Surprise discovery (behavior contradicts findings, unknown dependency, wrong assumption) → note in , finish or revert current step, transition to REFLECT. Do NOT silently update findings during EXECUTE.
state.md - Add comments where needed (
# DECISION D-NNN).references/decision-anchoring.md
- 步骤前检查清单在中:重置所有复选框为
state.md,在开始步骤前逐个勾选为[ ]。这是强制重读规则的文件化执行机制。[x] - 第一次执行迭代→创建(终极回退方案)。“Git状态”=变更前的提交哈希(恢复点)。
checkpoints/cp-000-iter1.md - 分步执行。每完成一步后通过步骤后检查门(见下文)。
- 风险变更前创建检查点(修改3个以上文件、共享模块、破坏性操作)。命名规则:(例如
cp-NNN-iterN.md)。NNN在所有迭代中全局递增。cp-001-iter2.md - 每成功完成一个步骤后提交:。
[iter-N/step-M] 描述 - 如果出现问题→立即停止。最多尝试2次修复(自主限制)。每次修复必须遵循“先回退”原则。
- 不可逆操作(数据库迁移、外部API调用、服务配置、未跟踪文件删除):在规划阶段的中标记步骤为
plan.md。完整流程参见[IRREVERSIBLE]。references/code-hygiene.md - 意外发现(行为与发现内容矛盾、未知依赖、错误假设)→在中记录,完成或回退当前步骤,转换到反思阶段。执行阶段禁止悄悄更新发现内容。
state.md - 在需要的地方添加注释(参见
# DECISION D-NNN)。references/decision-anchoring.md
Post-Step Gate (successful steps only — all 3 before moving on)
步骤后检查门(仅适用于成功完成的步骤——需全部满足才能进入下一步)
- — mark step
plan.md, advance marker, update complexity budget[x] - — move item Remaining → Completed, set next In Progress
progress.md - — update step number, append to change manifest
state.md
On failed step: skip gate. Follow Autonomy Leash (revert-first, 2 attempts max).
- ——标记步骤为
plan.md,更新进度标记,调整复杂度预算[x] - ——将任务从“待完成”移至“已完成”,设置下一个“进行中”任务
progress.md - ——更新步骤编号,追加到变更记录中
state.md
步骤失败时:跳过检查门。遵循自主限制规则(先回退,最多尝试2次)。
REFLECT
反思阶段
- Read (criteria + verification strategy) +
plan.mdbefore evaluating.progress.md - Read + relevant
findings.md— check if discoveries during EXECUTE contradict earlier findings. Note contradictions infindings/*.decisions.md - Read — know what rollback options exist before deciding next transition. Note available restore points in
checkpoints/*if transitioning to RE-PLAN.decisions.md - Cross-validate: every in plan.md must be "Completed" in progress.md. Fix drift first.
[x] - Run verification — execute each check defined in the Verification Strategy. Read , then record results: criterion, method, command/action, result (PASS/FAIL), evidence (output summary or log reference). See
verification.mdfor template.references/file-formats.md - Read — check 3-strike patterns.
decisions.md - Compare against written criteria, not memory. Run 5 Simplification Checks ().
references/complexity-control.md - Write (what happened, learned, root cause) +
decisions.md+progress.md.state.md
| Condition | → Transition |
|---|---|
All criteria verified PASS in | → CLOSE |
| Failure understood, new approach clear | → RE-PLAN |
| Unknowns need investigation, or findings contradicted | → EXPLORE (update findings first) |
- 评估前读取(验证标准+验证策略) +
plan.md。progress.md - 读取+ 相关的
findings.md文件——检查执行过程中的发现是否与之前的发现矛盾。在findings/*中记录矛盾点。decisions.md - 读取——在决定下一步转换前,明确可用的回退选项。在
checkpoints/*中记录可用的恢复点(如果转换到重新规划阶段)。decisions.md - 交叉验证:中所有标记为
plan.md的步骤必须在[x]中对应为“已完成”。先修正不一致的地方。progress.md - 执行验证——按照验证策略执行每个检查。读取,然后记录结果:验证标准、方法、命令/操作、结果(通过/失败)、证据(输出摘要或日志引用)。模板参见
verification.md。references/file-formats.md - 读取——检查三次失败模式。
decisions.md - 对照书面标准评估,而非凭记忆。运行5项简化检查()。
references/complexity-control.md - 写入(发生的情况、经验总结、根本原因) +
decisions.md+progress.md。state.md
| 条件 | 转换方向 |
|---|---|
| → 关闭 |
| 已理解失败原因,且明确更优方案 | → 重新规划 |
| 存在未知问题需要调查,或发现内容存在矛盾 | → 探索(先更新发现内容) |
RE-PLAN
重新规划阶段
- Read ,
decisions.md, relevantfindings.md.findings/* - Read — decide keep vs revert. Default: if unsure, revert to latest checkpoint. See
checkpoints/*for full decision framework.references/code-hygiene.md - If earlier findings proved wrong or incomplete → update +
findings.mdwith corrections. Mark corrections:findings/*+ what changed and why. Append, don't delete original text.[CORRECTED iter-N] - Write : log pivot + mandatory Complexity Assessment.
decisions.md - Write +
state.md(mark failed items, note pivot).progress.md - Present options to user → get approval → transition to PLAN.
- 读取,
decisions.md, 相关的findings.md文件。findings/* - 读取——决定保留还是回退。默认规则:如果不确定,回退到最新的检查点。完整决策框架参见
checkpoints/*。references/code-hygiene.md - 如果之前的发现被证明错误或不完整→更新+
findings.md文件,添加修正内容。标记修正:findings/*+ 变更内容及原因。追加内容,不要删除原始文本。[CORRECTED iter-N] - 写入:记录转向操作 + 强制复杂度评估。
decisions.md - 写入+
state.md(标记失败任务,记录转向)。progress.md - 向用户呈现选项→获得批准→转换到规划阶段。
Complexity Control (CRITICAL)
复杂度控制(至关重要)
Default response to failure = simplify, not add. See .
references/complexity-control.mdRevert-First — when something breaks: (1) STOP (2) revert? (3) delete? (4) one-liner? (5) none → REFLECT.
10-Line Rule — fix needs >10 new lines → it's not a fix → REFLECT.
3-Strike Rule — same area breaks 3× → RE-PLAN with fundamentally different approach. Revert to checkpoint covering the struck area.
Complexity Budget — tracked in plan.md: files added 0/3, abstractions 0/2, lines net-zero target.
Forbidden: wrapper cascades, config toggles, copy-paste, exception swallowing, type escapes, adapters, "temporary" workarounds.
Nuclear Option — iteration 5 + bloat >2× scope → recommend full revert to (or later checkpoint if user agrees). Otherwise proceed with caution. See .
cp-000references/complexity-control.md失败后的默认应对方式是简化,而非添加内容。参见。
references/complexity-control.md先回退原则——出现问题时:(1) 停止 (2) 回退?(3) 删除?(4) 单行修复?(5) 以上都不行→反思。
10行规则——修复需要新增超过10行代码→这不是有效的修复→反思。
三次失败规则——同一区域连续失败3次→采用完全不同的方案重新规划。回退到覆盖该区域的检查点。
复杂度预算——在中跟踪:新增文件数0/3,新增抽象层0/2,代码行数净零目标。
禁止操作:嵌套包装器、配置开关、复制粘贴、异常吞噬、类型逃逸、适配器、“临时” workaround。
终极方案——迭代次数达到5次 + 代码膨胀超过初始范围的2倍→建议完全回退到(或用户同意的更晚的检查点)。否则谨慎继续。参见。
plan.mdcp-000references/complexity-control.mdAutonomy Leash (CRITICAL)
自主限制(至关重要)
When a step fails during EXECUTE:
- 2 fix attempts max — each must follow Revert-First + 10-Line Rule.
- Both fail → STOP COMPLETELY. No 3rd fix. No silent alternative. No skipping ahead.
- Revert uncommitted changes to last clean commit. Codebase must be known-good before presenting.
- Present: what step should do, what happened, 2 attempts, root cause guess, available checkpoints for rollback.
- Transition → REFLECT. Log leash hit in . Wait for user.
state.md
Track attempts in . Resets on: user direction, new step, or RE-PLAN.
No exceptions. Unguided fix chains derail projects.
state.md执行阶段步骤失败时:
- 最多尝试2次修复——每次修复必须遵循先回退原则 + 10行规则。
- 两次尝试均失败→完全停止。禁止第三次修复,禁止悄悄改用替代方案,禁止跳过当前步骤。
- 将未提交的变更回退到最近的干净提交。在向用户汇报前,代码库必须处于已知的良好状态。
- 汇报内容:步骤预期目标、实际发生情况、两次尝试的内容、对根本原因的猜测、可用的回退检查点。
- 转换→反思阶段。在中记录触发自主限制。等待用户指令。
state.md
在中跟踪尝试次数。当用户给出新指令、进入新步骤或重新规划时,重置尝试次数。
无例外。无指导的修复链会导致项目偏离轨道。
state.mdCode Hygiene (CRITICAL)
代码卫生(至关重要)
Failed code must not survive. Track changes in change manifest in .
Failed step → revert all uncommitted. RE-PLAN → explicitly decide keep vs revert.
Codebase must be known-good before any PLAN. See .
state.mdreferences/code-hygiene.md失败的代码不得留存。在的变更记录中跟踪所有变更。
步骤失败→回退所有未提交的变更。重新规划→明确决定保留还是回退变更。
在任何规划阶段之前,代码库必须处于已知的良好状态。参见。
state.mdreferences/code-hygiene.mdDecision Anchoring (CRITICAL)
决策锚点(至关重要)
Code from failed iterations carries invisible context. Anchor
at point of impact — state what NOT to do and why. Audit at CLOSE.
See .
# DECISION D-NNNreferences/decision-anchoring.md失败迭代的代码带有不可见的上下文信息。在影响点添加注释——说明不应做什么及原因。关闭阶段审核这些锚点。
参见。
# DECISION D-NNNreferences/decision-anchoring.mdIteration Limits
迭代限制
Increment on PLAN → EXECUTE. Iteration 0 = EXPLORE-only (pre-plan). First real = iteration 1.
- Iteration 6+: hard STOP. Going in circles? Harder than scoped? Break into smaller tasks.
迭代次数在规划→执行阶段递增。迭代0=仅探索(规划前阶段)。第一次正式迭代=迭代1。
- 迭代6+:强制停止。是否在循环往复?任务比预期更难?拆分为更小的任务。
Recovery from Context Loss
上下文丢失恢复
- If is missing or corrupted: run
plans/.current_planto find plan directories, then recreate the pointer:bootstrap.mjs list(substitute actual directory name).echo "plan_YYYY-MM-DD_XXXXXXXX" > plans/.current_plan - → plan dir name
plans/.current_plan - → where you are
state.md - → current plan
plan.md - → what was tried / failed
decisions.md - → done vs remaining
progress.md - +
findings.md→ discovered contextfindings/* - → available rollback points and their git hashes
checkpoints/* - +
plans/FINDINGS.md→ cross-plan context from previous plansplans/DECISIONS.md - Resume from current state. Never start over.
- 如果丢失或损坏:运行
plans/.current_plan查找计划目录,然后重新创建指针:bootstrap.mjs list(替换为实际的目录名称)。echo "plan_YYYY-MM-DD_XXXXXXXX" > plans/.current_plan - → 计划目录名称
plans/.current_plan - → 当前所处状态
state.md - → 当前计划
plan.md - → 已尝试的方案/失败的内容
decisions.md - → 已完成 vs 待完成任务
progress.md - +
findings.md→ 已发现的上下文findings/* - → 可用的回退点及其Git哈希
checkpoints/* - +
plans/FINDINGS.md→ 来自之前计划的跨计划上下文plans/DECISIONS.md - 从当前状态恢复,切勿从头开始。
Git Integration
Git集成
- EXPLORE/PLAN/REFLECT/RE-PLAN: no commits.
- EXECUTE: commit per successful step . Failed step → revert uncommitted.
[iter-N/step-M] desc - RE-PLAN: keep successful commits if valid under new plan, or to revert. No partial state. Log choice in
git checkout <checkpoint-commit> -- ..decisions.md - CLOSE: final commit + tag.
- 探索/规划/反思/重新规划阶段:禁止提交。
- 执行阶段:每成功完成一个步骤提交一次,格式为。步骤失败→回退未提交的变更。
[iter-N/step-M] 描述 - 重新规划阶段:如果成功提交的内容符合新计划则保留,否则使用回退。禁止保留部分变更。在
git checkout <checkpoint-commit> -- .中记录选择。decisions.md - 关闭阶段:最终提交 + 打标签。
User Interaction
用户交互
| State | Behavior |
|---|---|
| EXPLORE | Ask focused questions, one at a time. Present findings. |
| PLAN | Present plan. Wait for approval. Re-present if modified. |
| EXECUTE | Report per step. Surface surprises. Ask before deviating. |
| REFLECT | Show expected vs actual. Propose: continue, re-plan, or close. |
| RE-PLAN | Reference decision log. Explain pivot. Get approval. |
| 状态 | 行为 |
|---|---|
| 探索 | 一次提出一个聚焦的问题,呈现发现内容。 |
| 规划 | 呈现规划方案,等待批准。修订后重新呈现。 |
| 执行 | 按步骤汇报进度,及时反馈意外情况。偏离计划前需询问用户。 |
| 反思 | 对比预期与实际结果,提出建议:继续、重新规划或关闭。 |
| 重新规划 | 参考决策日志,解释转向原因,获得用户批准。 |
When NOT to Use
不适用场景
Simple single-file changes, obvious solutions, known-root-cause bugs, or "just do it".
简单的单文件变更、解决方案明确的任务、已知根本原因的Bug,或“直接做”的任务。
References
参考文档
- — templates for all
references/file-formats.mdfiles{plan-dir} - — anti-complexity protocol, forbidden patterns
references/complexity-control.md - — change manifest, revert procedures
references/code-hygiene.md - — when/how to anchor decisions in code
references/decision-anchoring.md
- — 所有
references/file-formats.md文件的模板{plan-dir} - — 反复杂度协议、禁止模式
references/complexity-control.md - — 变更记录、回退流程
references/code-hygiene.md - — 在代码中锚定决策的时机与方法
references/decision-anchoring.md