@startuml git-branch-logic
!theme plain
title 程序逻辑流图：aide flow start 分支创建

start

:FlowTracker.start(phase, summary);

partition "Git 状态检查" {
  :GitIntegration.is_clean();

  if (工作目录干净?) then (否)
    :git add .;
    :git commit -m "保存未提交的变更";
  else (是)
  endif

  :GitIntegration.has_commits();

  if (有提交历史?) then (否)
    :创建 .gitkeep;
    :git commit -m "初始提交";
  else (是)
  endif
}

partition "分支创建" {
  :记录 source_branch = get_current_branch();
  :记录 start_commit = rev_parse_head();

  :BranchManager.get_next_branch_number();
  note right: 从 branches.json 读取

  :branch_name = "aide/" + 编号;
  :GitIntegration.create_branch(branch_name);
  :GitIntegration.checkout(branch_name);

  :BranchManager.record_branch_start();
  note right
    记录到 branches.json:
    - branch_name
    - source_branch
    - start_commit
    - task_id
    - task_summary
    - started_at
    - status: "active"
  end note

  :BranchManager.save_branches();
  note right: 同时生成 JSON 和 MD
}

:继续原有 start 逻辑;
:保存 FlowStatus;
:git add . && commit;

stop

@enduml
