kata-move-phase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<objective>
Move a pending phase to a different milestone or reorder phases within a milestone.
Purpose: Enable flexible phase reorganization (cross-milestone moves and within-milestone reordering).
Output: Phase moved/reordered, directories renamed, ROADMAP.md updated, STATE.md updated, git commit as historical record.
Supported operations:
- Cross-milestone move:
/kata-move-phase 3 to v1.6.0 - Reorder within milestone: or
/kata-move-phase 3 before 1</objective>/kata-move-phase 3 after 1
<execution_context>
@.planning/ROADMAP.md
@.planning/STATE.md
</execution_context>
<process>
<step name="parse_arguments">
Parse the command arguments. First arg is always the phase number (integer).
Detect operation type from second arg:
- + milestone version → cross-milestone move
"to" - or
"before"+ target phase number → reorder within milestone"after"
Cross-milestone move:
/kata-move-phase 3 to v1.6.0
Reorder within milestone:
- → Phase 3 takes position 1, everything shifts up
/kata-move-phase 3 before 1 - → Phase 3 takes position 2, phases 2+ shift up
/kata-move-phase 3 after 1
Validation:
- If no arguments or missing second arg:
ERROR: Phase number and operation required
Usage: /kata-move-phase <phase> to <milestone>
/kata-move-phase <phase> before|after <position>Exit.
- If second arg is not "to", "before", or "after":
ERROR: Invalid operation "{arg}"
Expected: to, before, or afterExit.
Store: PHASE_NUM, OPERATION (move|reorder), and either TARGET_MILESTONE or POSITION+TARGET_POSITION.
</step>
<step name="load_state">
Load project state:
bash
cat .planning/STATE.md 2>/dev/null
cat .planning/ROADMAP.md 2>/dev/nullParse current milestone version from ROADMAP.md (the milestone marked "In Progress").
</step>
<step name="validate_phase_exists">
Verify the phase exists in ROADMAP.md and find its directory:
- Search for heading within the current milestone
#### Phase {N}: - Use universal phase discovery (search active/pending/completed with padded and unpadded names, fallback to flat)
- If not found: + list available phases. Exit. </step>
ERROR: Phase {N} not found in roadmap
- Must be in pending/ (not active or completed). If not: . Exit.
ERROR: Phase {N} is in {state}/ and cannot be moved - Must not have SUMMARY.md files (no executed plans). If found: . Exit. </step>
ERROR: Phase {N} has completed work
- Target milestone heading must exist in ROADMAP.md. If not: + list available. Exit.
ERROR: Milestone {target} not found - Target must differ from source. If same: Exit. </step>
ERROR: Phase already in {milestone}. Use before/after to reorder.
Validate the target position phase exists in the same milestone:
- Target position phase must exist in ROADMAP.md within the current milestone
- Target can be any state (active, pending, completed) since we're reordering the roadmap listing
- The phase being moved must be pending (already validated in validate_phase_movable)
Calculate the effective target position:
- → target position = N (phase takes position N, everything at N+ shifts up)
before N - → target position = N+1 (phase takes position N+1, everything at N+1+ shifts up)
after N
If target position phase not found:
ERROR: Phase {target_position} not found in current milestone
Available phases: [list phase numbers]Exit.
</step>
<step name="confirm_reorder">
**Reorder only.** Skip for cross-milestone moves.
Show the planned reorder and wait for confirmation:
Reordering Phase {N}: {Name}
Current order:
Phase 1: {name}
Phase 2: {name}
Phase 3: {name}
New order:
Phase 1: {name} (was Phase 3)
Phase 2: {name} (was Phase 1)
Phase 3: {name} (was Phase 2)
This will renumber all phase directories and update ROADMAP.md.
Proceed? (y/n)Wait for confirmation.
</step>
<step name="reorder_roadmap">
**Reorder only.** Skip for cross-milestone moves.
Update ROADMAP.md to reflect the new phase order:
- Extract all phase sections within the current milestone
- Remove the moving phase section from its current position
- Insert it at the target position
- Renumber ALL phase headings in the milestone sequentially (1, 2, 3, ...)
- Update all references within the milestone:
- Phase headings: ->
#### Phase {old}:#### Phase {new}: - Phase list entries
- Progress table rows
- Plan references: ->
{old}-01:{new}-01: - Dependency references: ->
Depends on: Phase {old}Depends on: Phase {new} - Decimal phase references if any
- Phase headings:
Write updated ROADMAP.md.
</step>
<step name="renumber_all_directories">
**Reorder only.** Skip for cross-milestone moves.
Rename ALL phase directories in the milestone to match new numbering. Use a three-pass approach to avoid collision:
- Pass 1: Move the reordering phase to a temp name ()
tmp-{slug} - Pass 2: Renumber all remaining phases sequentially. Process order matters:
- Phases shifting down (higher->lower): process lowest first
- Phases shifting up (lower->higher): process highest first
- For each: find across state subdirectories, rename directory and internal files
- Pass 3: Move temp directory to its final numbered position, rename internal files
Handle decimal phases: they follow their parent integer phase and renumber accordingly.
</step>
<step name="calculate_destination_number">
**Cross-milestone move only.** Skip for reorder operations.
Find next phase number in target milestone: parse headings, take highest + 1 (or 1 if empty). Format as two-digit padded.
</step>
<step name="confirm_move">
**Cross-milestone move only.** Skip for reorder operations.
#### Phase N:Show: source milestone, target milestone, new phase number, directory rename, number of phases to renumber in source. Wait for confirmation.
</step>
<step name="remove_from_source_milestone">
**Cross-milestone move only.** Skip for reorder operations.
Remove phase section from source milestone in ROADMAP.md and renumber remaining phases to close the gap. Follow the same renumbering approach as kata-remove-phase:
- Phase headings, list entries, progress table rows
- Plan references (->
{old}-01:){new}-01: - Dependency references (->
Depends on: Phase {old})Phase {new} - Decimal phase references </step>
Insert phase section into target milestone in ROADMAP.md at the calculated destination number. Preserve goal, requirements, success criteria. Remove or note cross-milestone dependency references that no longer apply.
</step>
<step name="rename_phase_directory">
**Cross-milestone move only.** Skip for reorder operations (handled by renumber_all_directories).
Rename phase directory to new number within pending/. Rename all files inside (PLAN.md, RESEARCH.md, etc.) to match. Handle decimal phases (N.1, N.2) by moving them with the parent, renumbering to NEW_NUM.1, NEW_NUM.2.
</step>
<step name="renumber_source_directories">
**Cross-milestone move only.** Skip for reorder operations (handled by renumber_all_directories).
Renumber directories of phases that shifted in the source milestone. Process ascending order (for downward shifts). For each: find across state subdirectories, rename directory and internal files within same state.
</step>
<step name="update_state">
Update STATE.md:
For cross-milestone move:
- Add roadmap evolution note:
markdown
- **Phase {N} moved from {source_milestone} to {target_milestone}** as Phase {NEW_NUM}- Update total phase count if the source milestone is the current milestone
- Recalculate progress percentage
For reorder:
- Add roadmap evolution note:
markdown
- **Phase {N} reordered {before|after} Phase {M}** in {milestone}- Phase count unchanged (same milestone, same phases)
Both operations: Update REQUIREMENTS.md traceability if requirements reference affected phases. Update phase numbers in traceability table for all renumbered phases.
</step>
<step name="commit">
Check planning config:
bash
COMMIT_PLANNING_DOCS=$(cat .planning/config.json 2>/dev/null | grep -o '"commit_docs"[[:space:]]*:[[:space:]]*[^,}]*' | grep -o 'true\|false' || echo "true")
git check-ignore -q .planning 2>/dev/null && COMMIT_PLANNING_DOCS=falseIf : Skip git operations
COMMIT_PLANNING_DOCS=falseIf (default):
COMMIT_PLANNING_DOCS=truebash
git add .planning/<objective>
将待处理阶段移动到不同的里程碑,或在里程碑内重新排序阶段。
目的:实现灵活的阶段重组(跨里程碑移动和里程碑内重新排序)。
输出:阶段已移动/重新排序、目录重命名、ROADMAP.md已更新、STATE.md已更新、git提交作为历史记录。
支持的操作:
- 跨里程碑移动:
/kata-move-phase 3 to v1.6.0 - 里程碑内重新排序:或
/kata-move-phase 3 before 1</objective>/kata-move-phase 3 after 1
<execution_context>
@.planning/ROADMAP.md
@.planning/STATE.md
</execution_context>
<process>
<step name="parse_arguments">
解析命令参数。第一个参数始终是阶段编号(整数)。
根据第二个参数检测操作类型:
- + 里程碑版本 → 跨里程碑移动
"to" - 或
"before"+ 目标阶段编号 → 里程碑内重新排序"after"
跨里程碑移动示例:
/kata-move-phase 3 to v1.6.0
里程碑内重新排序示例:
- → 阶段3移至位置1,其余阶段依次后移
/kata-move-phase 3 before 1 - → 阶段3移至位置2,阶段2及之后的阶段依次后移
/kata-move-phase 3 after 1
验证规则:
- 若无参数或缺少第二个参数:
ERROR: Phase number and operation required
Usage: /kata-move-phase <phase> to <milestone>
/kata-move-phase <phase> before|after <position>退出操作。
- 若第二个参数不是"to"、"before"或"after":
ERROR: Invalid operation "{arg}"
Expected: to, before, or after退出操作。
存储信息:PHASE_NUM(阶段编号)、OPERATION(操作类型:move|reorder),以及TARGET_MILESTONE(目标里程碑)或POSITION+TARGET_POSITION(位置+目标位置)。
</step>
<step name="load_state">
加载项目状态:
bash
cat .planning/STATE.md 2>/dev/null
cat .planning/ROADMAP.md 2>/dev/null从ROADMAP.md中解析当前里程碑版本(标记为"In Progress"的里程碑)。
</step>
<step name="validate_phase_exists">
验证阶段在ROADMAP.md中存在,并找到其对应的目录:
- 在当前里程碑内搜索标题
#### Phase {N}: - 使用通用阶段发现机制(在active/pending/completed目录中搜索带填充和不带填充名称的阶段,未找到则查找扁平结构)
- 若未找到:输出并列出可用阶段,然后退出操作。 </step>
ERROR: Phase {N} not found in roadmap
- 阶段必须处于pending/目录下(非active或completed状态)。若不满足:输出,然后退出操作。
ERROR: Phase {N} is in {state}/ and cannot be moved - 阶段不能包含SUMMARY.md文件(即无已执行的计划)。若存在该文件:输出,然后退出操作。 </step>
ERROR: Phase {N} has completed work
- 目标里程碑标题必须在ROADMAP.md中存在。若不存在:输出并列出可用里程碑,然后退出操作。
ERROR: Milestone {target} not found - 目标里程碑必须与源里程碑不同。若相同:输出,然后退出操作。 </step>
ERROR: Phase already in {milestone}. Use before/after to reorder.
验证目标位置的阶段在同一里程碑中存在:
- 目标位置的阶段必须在当前里程碑的ROADMAP.md中存在
- 目标阶段可以是任何状态(active、pending、completed),因为我们仅重新排序路线图列表
- 待移动的阶段必须处于pending状态(已在validate_phase_movable步骤中验证)
计算实际目标位置:
- → 目标位置 = N(阶段移至位置N,N及之后的阶段依次后移)
before N - → 目标位置 = N+1(阶段移至位置N+1,N+1及之后的阶段依次后移)
after N
若目标位置的阶段未找到:
ERROR: Phase {target_position} not found in current milestone
Available phases: [list phase numbers]退出操作。
</step>
<step name="confirm_reorder">
**仅适用于重新排序操作,跨里程碑移动操作跳过此步骤。**
显示计划的重新排序内容并等待确认:
Reordering Phase {N}: {Name}
Current order:
Phase 1: {name}
Phase 2: {name}
Phase 3: {name}
New order:
Phase 1: {name} (was Phase 3)
Phase 2: {name} (was Phase 1)
Phase 3: {name} (was Phase 2)
This will renumber all phase directories and update ROADMAP.md.
Proceed? (y/n)等待用户确认。
</step>
<step name="reorder_roadmap">
**仅适用于重新排序操作,跨里程碑移动操作跳过此步骤。**
更新ROADMAP.md以反映新的阶段顺序:
- 提取当前里程碑内的所有阶段部分
- 将待移动的阶段部分从当前位置移除
- 将其插入到目标位置
- 按顺序重新编号里程碑内的所有阶段标题(1、2、3……)
- 更新里程碑内的所有引用:
- 阶段标题:→
#### Phase {old}:#### Phase {new}: - 阶段列表条目
- 进度表格行
- 计划引用:→
{old}-01:{new}-01: - 依赖引用:→
Depends on: Phase {old}Depends on: Phase {new} - 若存在小数阶段的引用也需更新
- 阶段标题:
写入更新后的ROADMAP.md。
</step>
<step name="renumber_all_directories">
**仅适用于重新排序操作,跨里程碑移动操作跳过此步骤。**
重命名里程碑内的所有阶段目录以匹配新编号。采用三步法避免命名冲突:
- 第一步: 将待重新排序的阶段移至临时名称()
tmp-{slug} - 第二步: 按顺序重新编号所有剩余阶段。处理顺序很重要:
- 阶段编号下移(从高到低):从最低编号开始处理
- 阶段编号上移(从低到高):从最高编号开始处理
- 对于每个阶段:在状态子目录中查找,重命名目录及内部文件
- 第三步: 将临时目录移至最终编号位置,重命名内部文件
处理小数阶段:小数阶段跟随其父整数阶段进行相应重编号。
</step>
<step name="calculate_destination_number">
**仅适用于跨里程碑移动操作,重新排序操作跳过此步骤。**
查找目标里程碑中的下一个阶段编号:解析标题,取最大编号+1(若为空则为1)。格式为两位数字填充。
</step>
<step name="confirm_move">
**仅适用于跨里程碑移动操作,重新排序操作跳过此步骤。**
#### Phase N:显示以下信息并等待确认:源里程碑、目标里程碑、新阶段编号、目录重命名信息、源里程碑中需重编号的阶段数量。
</step>
<step name="remove_from_source_milestone">
**仅适用于跨里程碑移动操作,重新排序操作跳过此步骤。**
从ROADMAP.md的源里程碑中移除阶段部分,并重新编号剩余阶段以填补空缺。遵循与kata-remove-phase相同的重编号规则:
- 阶段标题、列表条目、进度表格行
- 计划引用(→
{old}-01:){new}-01: - 依赖引用(→
Depends on: Phase {old})Phase {new} - 小数阶段引用 </step>
将阶段部分插入到ROADMAP.md的目标里程碑中,使用计算得出的目标编号。保留目标、需求、成功标准。移除或标注不再适用的跨里程碑依赖引用。
</step>
<step name="rename_phase_directory">
**仅适用于跨里程碑移动操作,重新排序操作跳过此步骤(由renumber_all_directories处理)。**
将阶段目录重命名为pending/下的新编号。重命名目录内的所有文件(PLAN.md、RESEARCH.md等)以匹配新编号。处理小数阶段(N.1、N.2):将其与父阶段一起移动,重命名为NEW_NUM.1、NEW_NUM.2。
</step>
<step name="renumber_source_directories">
**仅适用于跨里程碑移动操作,重新排序操作跳过此步骤(由renumber_all_directories处理)。**
对源里程碑中编号发生变化的阶段目录进行重编号。按升序处理(适用于编号下移的情况)。对于每个阶段:在状态子目录中查找,重命名同一状态下的目录及内部文件。
</step>
<step name="update_state">
更新STATE.md:
跨里程碑移动操作:
- 添加路线图变更记录:
markdown
- **Phase {N} moved from {source_milestone} to {target_milestone}** as Phase {NEW_NUM}- 若源里程碑为当前里程碑,更新总阶段数
- 重新计算进度百分比
重新排序操作:
- 添加路线图变更记录:
markdown
- **Phase {N} reordered {before|after} Phase {M}** in {milestone}- 阶段总数不变(同一里程碑,阶段未增减)
两种操作通用: 若需求引用受影响的阶段,更新REQUIREMENTS.md的可追溯性。为所有重编号的阶段更新可追溯性表格中的阶段编号。
</step>
<step name="commit">
检查规划配置:
bash
COMMIT_PLANNING_DOCS=$(cat .planning/config.json 2>/dev/null | grep -o '"commit_docs"[[:space:]]*:[[:space:]]*[^,}]*' | grep -o 'true\|false' || echo "true")
git check-ignore -q .planning 2>/dev/null && COMMIT_PLANNING_DOCS=false若: 跳过git操作
COMMIT_PLANNING_DOCS=false若(默认值):
COMMIT_PLANNING_DOCS=truebash
git add .planning/Cross-milestone move:
跨里程碑移动操作:
git commit -m "chore: move phase {N} to {target_milestone}"
git commit -m "chore: move phase {N} to {target_milestone}"
Reorder:
重新排序操作:
git commit -m "chore: reorder phase {N} {before|after} {M}"
</step>
<step name="completion">
Present completion summary showing: operation performed, directories renamed, phases renumbered, files updated, commit message. Then offer next actions: `/kata-track-progress`, continue current phase, review roadmap.
</step>
</process>
<anti_patterns>
- Don't move active or completed phases (only pending phases can be moved/reordered)
- Don't move phases with executed plans (SUMMARY.md exists)
- Don't move to the same milestone (use reorder instead)
- Don't reorder to the same position (no-op)
- Don't forget decimal phases (they move with parent integer phase)
- Don't commit if commit_docs is false
- Don't leave gaps in phase numbering after move or reorder
- Don't modify phases outside the source and target milestones
- Don't rename directories without the two-pass temp approach (avoids collisions during reorder)
</anti_patterns>
<edge_cases>
**Phase has PLAN.md files but no SUMMARY.md:**
- Allowed. Rename plan files inside the directory as part of the move/reorder.
- Update plan frontmatter phase references.
**Target milestone is empty (no phases):**
- First phase becomes Phase 1.
- `calculate_destination_number` handles this (NEW_NUM=1 when HIGHEST is empty).
**Last phase in source milestone removed:**
- No renumbering needed in source milestone.
- Source milestone section in ROADMAP.md still has its heading.
**Decimal phases under moved integer phase:**
- Find all decimal phases (N.1, N.2) belonging to the moved integer phase.
- Move them together with the parent.
- Renumber to NEW_NUM.1, NEW_NUM.2 at destination.
**Phase directory doesn't exist yet:**
- Phase may be in ROADMAP.md but directory not created.
- Skip directory operations, proceed with ROADMAP.md updates only.
- Note in completion summary: "No directory to move (phase not yet created)"
**Reorder: moving to adjacent position:**
- `before N+1` or `after N-1` when phase is at position N is a no-op.
- Detect and report: "Phase {N} is already at that position."
**Reorder: only two phases in milestone:**
- Swap positions. Both directories and all references renumbered.
</edge_cases>
<success_criteria>
**Cross-milestone move** is complete when:
- [ ] Source phase validated as pending/unstarted
- [ ] Target milestone validated as existing and different from source
- [ ] Phase section removed from source milestone in ROADMAP.md
- [ ] Remaining source phases renumbered to close gap
- [ ] Phase section added to target milestone with correct number
- [ ] Phase directory renamed to match new number
- [ ] Files inside directory renamed ({old}-NN-PLAN.md -> {new}-NN-PLAN.md)
- [ ] Decimal phases moved with parent (if any)
- [ ] Source directories renumbered (if phases shifted)
- [ ] STATE.md updated with roadmap evolution note
- [ ] Changes committed with descriptive message
- [ ] No gaps in phase numbering at source or destination
**Reorder** is complete when:
- [ ] Phase validated as pending/unstarted
- [ ] Target position validated as existing in same milestone
- [ ] Phase sections reordered in ROADMAP.md
- [ ] All phases in milestone renumbered sequentially
- [ ] All phase directories renamed (two-pass temp approach)
- [ ] Files inside directories renamed to match new numbers
- [ ] Decimal phases renumbered with parent (if any)
- [ ] STATE.md updated with roadmap evolution note
- [ ] Changes committed with descriptive message
- [ ] No gaps in phase numbering
**Both operations:** User informed of all changes.
</success_criteria>git commit -m "chore: reorder phase {N} {before|after} {M}"
</step>
<step name="completion">
显示完成摘要,内容包括:执行的操作、重命名的目录、重编号的阶段、更新的文件、提交信息。然后提供后续操作选项:`/kata-track-progress`、继续当前阶段、查看路线图。
</step>
</process>
<anti_patterns>
- 不要移动active或completed状态的阶段(仅pending状态的阶段可被移动/重新排序)
- 不要移动包含已执行计划的阶段(存在SUMMARY.md文件)
- 不要将阶段移动到同一里程碑(应使用重新排序操作)
- 不要将阶段重新排序到当前位置(无意义操作)
- 不要遗漏小数阶段(它们随父整数阶段一起移动)
- 若commit_docs为false,不要执行提交操作
- 移动或重新排序后不要留下阶段编号空缺
- 不要修改源里程碑和目标里程碑之外的阶段
- 不要在重新排序时不使用两步临时法重命名目录(避免命名冲突)
</anti_patterns>
<edge_cases>
**阶段包含PLAN.md文件但无SUMMARY.md文件:**
- 允许操作。在移动/重新排序过程中重命名目录内的计划文件。
- 更新计划前置元数据中的阶段引用。
**目标里程碑为空(无阶段):**
- 第一个阶段成为Phase 1。
- `calculate_destination_number`步骤会处理此情况(当HIGHEST为空时,NEW_NUM=1)。
**源里程碑的最后一个阶段被移除:**
- 源里程碑无需重编号。
- ROADMAP.md中的源里程碑部分仍保留其标题。
**被移动的整数阶段下包含小数阶段:**
- 查找所有属于该整数阶段的小数阶段(N.1、N.2)。
- 将它们与父阶段一起移动。
- 在目标位置重命名为NEW_NUM.1、NEW_NUM.2。
**阶段目录尚未创建:**
- 阶段可能已在ROADMAP.md中存在但目录未创建。
- 跳过目录操作,仅执行ROADMAP.md的更新。
- 在完成摘要中注明:"No directory to move (phase not yet created)"
**重新排序:移动到相邻位置:**
- 当阶段位于位置N时,执行`before N+1`或`after N-1`属于无意义操作。
- 检测到后输出:"Phase {N} is already at that position."
**重新排序:里程碑内仅有两个阶段:**
- 交换位置。重命名两个目录及所有引用。
</edge_cases>
<success_criteria>
**跨里程碑移动操作**完成的标志:
- [ ] 源阶段已验证为pending/unstarted状态
- [ ] 目标里程碑已验证为存在且与源里程碑不同
- [ ] 阶段部分已从ROADMAP.md的源里程碑中移除
- [ ] 源里程碑的剩余阶段已重编号以填补空缺
- [ ] 阶段部分已添加到目标里程碑并使用正确编号
- [ ] 阶段目录已重命名以匹配新编号
- [ ] 目录内的文件已重命名(`{old}-NN-PLAN.md` → `{new}-NN-PLAN.md`)
- [ ] 小数阶段已随父阶段一起移动(若有)
- [ ] 源目录已重编号(若阶段编号发生变化)
- [ ] STATE.md已添加路线图变更记录
- [ ] 变更已通过描述性信息提交
- [ ] 源里程碑和目标里程碑的阶段编号无空缺
**重新排序操作**完成的标志:
- [ ] 阶段已验证为pending/unstarted状态
- [ ] 目标位置已验证为在同一里程碑中存在
- [ ] ROADMAP.md中的阶段部分已重新排序
- [ ] 里程碑内的所有阶段已按顺序重编号
- [ ] 所有阶段目录已重命名(使用两步临时法)
- [ ] 目录内的文件已重命名以匹配新编号
- [ ] 小数阶段已随父阶段一起重编号(若有)
- [ ] STATE.md已添加路线图变更记录
- [ ] 变更已通过描述性信息提交
- [ ] 阶段编号无空缺
**两种操作通用:** 已向用户告知所有变更内容。
</success_criteria>