kata-insert-phase

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<objective> Insert a decimal phase for urgent work discovered mid-milestone that must be completed between existing integer phases.
Uses decimal numbering (72.1, 72.2, etc.) to preserve the logical sequence of planned phases while accommodating urgent insertions.
Purpose: Handle urgent work discovered during execution without renumbering entire roadmap. </objective>
<execution_context> @.planning/ROADMAP.md @.planning/STATE.md </execution_context>
<process> <step name="parse_arguments"> Parse the command arguments: - First argument: integer phase number to insert after - Remaining arguments: phase description
Example:
/kata-insert-phase 72 Fix critical auth bug
→ after = 72 → description = "Fix critical auth bug"
Validation:
bash
if [ $# -lt 2 ]; then
  echo "ERROR: Both phase number and description required"
  echo "Usage: /kata-insert-phase <after> <description>"
  echo "Example: /kata-insert-phase 72 Fix critical auth bug"
  exit 1
fi
Parse first argument as integer:
bash
after_phase=$1
shift
description="$*"
<objective> 在里程碑执行中途发现的紧急工作,需在现有整数阶段之间插入一个小数阶段来处理。
使用十进制编号(如72.1、72.2等),在保留原计划阶段逻辑顺序的同时,适配紧急插入的工作。
目的:在不重新编号整个路线图的情况下,处理执行过程中发现的紧急工作。 </objective>
<execution_context> @.planning/ROADMAP.md @.planning/STATE.md </execution_context>
<process> <step name="parse_arguments"> 解析命令参数: - 第一个参数:要在其后插入的整数阶段编号 - 剩余参数:阶段描述
示例:
/kata-insert-phase 72 Fix critical auth bug
→ after = 72 → description = "修复严重认证漏洞"
验证:
bash
if [ $# -lt 2 ]; then
  echo "ERROR: Both phase number and description required"
  echo "Usage: /kata-insert-phase <after> <description>"
  echo "Example: /kata-insert-phase 72 Fix critical auth bug"
  exit 1
fi
将第一个参数解析为整数:
bash
after_phase=$1
shift
description="$*"

Validate after_phase is an integer

Validate after_phase is an integer

if ! [[ "$after_phase" =~ ^[0-9]+$ ]]; then echo "ERROR: Phase number must be an integer" exit 1 fi

</step>

<step name="preflight_roadmap_format">
**Pre-flight: Check roadmap format (auto-migration)**

If ROADMAP.md exists, check format and auto-migrate if old:

```bash
if [ -f .planning/ROADMAP.md ]; then
  bash ../kata-doctor/scripts/check-roadmap-format.sh 2>/dev/null
  FORMAT_EXIT=$?
  
  if [ $FORMAT_EXIT -eq 1 ]; then
    echo "Old roadmap format detected. Running auto-migration..."
  fi
fi
If exit code 1 (old format):
Invoke kata-doctor in auto mode:
Skill("kata-doctor", "--auto")
Continue after migration completes.
If exit code 0 or 2: Continue silently. </step>
<step name="load_roadmap"> Load the roadmap file:
bash
if [ -f .planning/ROADMAP.md ]; then
  ROADMAP=".planning/ROADMAP.md"
else
  echo "ERROR: No roadmap found (.planning/ROADMAP.md)"
  exit 1
fi
Read roadmap content for parsing. </step>
<step name="verify_target_phase"> Verify that the target phase exists in the roadmap:
  1. Search for "### Phase {after_phase}:" heading
  2. If not found:
    ERROR: Phase {after_phase} not found in roadmap
    Available phases: [list phase numbers]
    Exit.
  3. Verify phase is in current milestone (not completed/archived) </step>
<step name="find_existing_decimals"> Find existing decimal phases after the target phase:
  1. Search for all "### Phase {after_phase}.N:" headings
  2. Extract decimal suffixes (e.g., for Phase 72: find 72.1, 72.2, 72.3)
  3. Find the highest decimal suffix
  4. Calculate next decimal: max + 1
Examples:
  • Phase 72 with no decimals → next is 72.1
  • Phase 72 with 72.1 → next is 72.2
  • Phase 72 with 72.1, 72.2 → next is 72.3
Store as:
decimal_phase="$(printf "%02d" $after_phase).${next_decimal}"
</step>
<step name="generate_slug"> Convert the phase description to a kebab-case slug:
bash
slug=$(echo "$description" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
Phase directory name:
{decimal-phase}-{slug}
Example:
06.1-fix-critical-auth-bug
(phase 6 insertion) </step>
<step name="create_phase_directory"> Create the phase directory structure:
bash
phase_dir=".planning/phases/pending/${decimal_phase}-${slug}"
mkdir -p "$phase_dir"
Confirm: "Created directory: $phase_dir" </step>
<step name="update_roadmap"> Insert the new phase entry into the roadmap:
  1. Find insertion point: immediately after Phase {after_phase}'s content (before next phase heading or "---")
  2. Insert new phase heading with (INSERTED) marker:
    ### Phase {decimal_phase}: {Description} (INSERTED)
    
    **Goal:** [Urgent work - to be planned]
    **Depends on:** Phase {after_phase}
    **Plans:** 0 plans
    
    Plans:
    - [ ] TBD (run /kata-plan-phase {decimal_phase} to break down)
    
    **Details:**
    [To be added during planning]
  3. Write updated roadmap back to file
The "(INSERTED)" marker helps identify decimal phases as urgent insertions.
Preserve all other content exactly (formatting, spacing, other phases). </step>
<step name="update_project_state"> Update STATE.md to reflect the inserted phase:
  1. Read
    .planning/STATE.md
  2. Under "## Accumulated Context" → "### Roadmap Evolution" add entry:
    - Phase {decimal_phase} inserted after Phase {after_phase}: {description} (URGENT)
If "Roadmap Evolution" section doesn't exist, create it.
Add note about insertion reason if appropriate. </step>
<step name="completion"> Present completion summary:
Phase {decimal_phase} inserted after Phase {after_phase}:
- Description: {description}
- Directory: .planning/phases/{decimal-phase}-{slug}/
- Status: Not planned yet
- Marker: (INSERTED) - indicates urgent work

Roadmap updated: {roadmap-path}
Project state updated: .planning/STATE.md

---
if ! [[ "$after_phase" =~ ^[0-9]+$ ]]; then echo "ERROR: Phase number must be an integer" exit 1 fi

</step>

<step name="preflight_roadmap_format">
**预检查:检查路线图格式(自动迁移)**

如果ROADMAP.md存在,检查格式,若为旧格式则自动迁移:

```bash
if [ -f .planning/ROADMAP.md ]; then
  bash ../kata-doctor/scripts/check-roadmap-format.sh 2>/dev/null
  FORMAT_EXIT=$?
  
  if [ $FORMAT_EXIT -eq 1 ]; then
    echo "Old roadmap format detected. Running auto-migration..."
  fi
fi
如果退出码为1(旧格式):
调用kata-doctor自动模式:
Skill("kata-doctor", "--auto")
迁移完成后继续执行。
如果退出码为0或2: 静默继续。 </step>
<step name="load_roadmap"> 加载路线图文件:
bash
if [ -f .planning/ROADMAP.md ]; then
  ROADMAP=".planning/ROADMAP.md"
else
  echo "ERROR: No roadmap found (.planning/ROADMAP.md)"
  exit 1
fi
读取路线图内容以供解析。 </step>
<step name="verify_target_phase"> 验证目标阶段是否存在于路线图中:
  1. 搜索"### Phase {after_phase}:"标题
  2. 如果未找到:
    ERROR: Phase {after_phase} not found in roadmap
    Available phases: [列出所有阶段编号]
    退出执行。
  3. 验证该阶段处于当前里程碑(未完成/未归档) </step>
<step name="find_existing_decimals"> 查找目标阶段之后已存在的小数阶段:
  1. 搜索所有"### Phase {after_phase}.N:"标题
  2. 提取小数后缀(例如,对于Phase 72:查找72.1、72.2、72.3)
  3. 找到最大的小数后缀
  4. 计算下一个小数:最大值 + 1
示例:
  • Phase 72无小数阶段 → 下一个是72.1
  • Phase 72已有72.1 → 下一个是72.2
  • Phase 72已有72.1、72.2 → 下一个是72.3
存储为:
decimal_phase="$(printf "%02d" $after_phase).${next_decimal}"
</step>
<step name="generate_slug"> 将阶段描述转换为短横线分隔的slug格式:
bash
slug=$(echo "$description" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
阶段目录名称:
{decimal-phase}-{slug}
示例:
06.1-fix-critical-auth-bug
(插入到Phase 6之后) </step>
<step name="create_phase_directory"> 创建阶段目录结构:
bash
phase_dir=".planning/phases/pending/${decimal_phase}-${slug}"
mkdir -p "$phase_dir"
确认提示:"Created directory: $phase_dir" </step>
<step name="update_roadmap"> 将新阶段条目插入到路线图中:
  1. 找到插入位置:紧跟在Phase {after_phase}的内容之后(在下一个阶段标题或"---"之前)
  2. 插入带有(INSERTED)标记的新阶段标题:
    ### Phase {decimal_phase}: {Description} (INSERTED)
    
    **Goal:** [紧急工作 - 待规划]
    **Depends on:** Phase {after_phase}
    **Plans:** 0 plans
    
    Plans:
    - [ ] TBD (运行 /kata-plan-phase {decimal_phase} 进行拆分)
    
    **Details:**
    [规划过程中补充]
  3. 将更新后的路线图写回文件
"(INSERTED)"标记用于标识小数阶段为紧急插入项。
完全保留其他所有内容(格式、空格、其他阶段)。 </step>
<step name="update_project_state"> 更新STATE.md以反映插入的阶段:
  1. 读取
    .planning/STATE.md
  2. 在"## Accumulated Context" → "### Roadmap Evolution"下添加条目:
    - Phase {decimal_phase} inserted after Phase {after_phase}: {description} (URGENT)
如果"Roadmap Evolution"部分不存在,则创建该部分。
如有必要,添加插入原因的说明。 </step>
<step name="completion"> 展示完成摘要:
Phase {decimal_phase} inserted after Phase {after_phase}:
- Description: {description}
- Directory: .planning/phases/{decimal-phase}-{slug}/
- Status: 尚未规划
- Marker: (INSERTED) - 表示紧急工作

Roadmap updated: {roadmap-path}
Project state updated: .planning/STATE.md

---

▶ Next Up

▶ 下一步

Phase {decimal_phase}: {description} — urgent insertion
/kata-plan-phase {decimal_phase}
<sub>
/clear
first → fresh context window</sub>

Also available:
  • Review insertion impact: Check if Phase {next_integer} dependencies still make sense
  • Review roadmap

</step>

</process>

<anti_patterns>

- Don't use this for planned work at end of milestone (use /kata-add-phase)
- Don't insert before Phase 1 (decimal 0.1 makes no sense)
- Don't renumber existing phases
- Don't modify the target phase content
- Don't create plans yet (that's /kata-plan-phase)
- Don't commit changes (user decides when to commit)
  </anti_patterns>

<success_criteria>
Phase insertion is complete when:

- [ ] Phase directory created: `.planning/phases/pending/{N.M}-{slug}/`
- [ ] Roadmap updated with new phase entry (includes "(INSERTED)" marker)
- [ ] Phase inserted in correct position (after target phase, before next integer phase)
- [ ] STATE.md updated with roadmap evolution note
- [ ] Decimal number calculated correctly (based on existing decimals)
- [ ] User informed of next steps and dependency implications
      </success_criteria>
Phase {decimal_phase}: {description} — 紧急插入项
/kata-plan-phase {decimal_phase}
<sub>先执行
/clear
→ 刷新上下文窗口</sub>

其他可用操作:
  • 检查插入影响:确认Phase {next_integer}的依赖关系是否仍然合理
  • 查看路线图

</step>

</process>

<anti_patterns>

- 不要将此用于里程碑末尾的计划工作(使用/kata-add-phase)
- 不要在Phase 1之前插入(0.1阶段没有意义)
- 不要重新编号现有阶段
- 不要修改目标阶段的内容
- 暂时不要创建计划(这是/kata-plan-phase的功能)
- 不要提交更改(由用户决定何时提交)
  </anti_patterns>

<success_criteria>
阶段插入完成的判定标准:

- [ ] 已创建阶段目录:`.planning/phases/pending/{N.M}-{slug}/`
- [ ] 路线图已更新,包含新阶段条目(带有"(INSERTED)"标记)
- [ ] 阶段插入到正确位置(目标阶段之后,下一个整数阶段之前)
- [ ] STATE.md已更新路线图演进记录
- [ ] 小数编号计算正确(基于已存在的小数阶段)
- [ ] 已告知用户后续步骤和依赖影响
      </success_criteria>