{
  "schema_version": 3,
  "diagram_type": "lifecycle",
  "meta": {
    "title": "Issue worktree 生命週期",
    "locale": "zh-TW",
    "quality_profile": "standard",
    "output": "docs/workflow/diagrams/03-worktree.html"
  },
  "mainPath": [
    "created",
    "implementing",
    "verifying",
    "merging",
    "pushed",
    "removed"
  ],
  "states": [
    {
      "id": "created",
      "type": "start",
      "label": "建立",
      "sublabel": "從整合分支開出",
      "tag": "orca-worktree-create",
      "step": "01"
    },
    {
      "id": "implementing",
      "type": "active",
      "label": "實作中",
      "sublabel": "單一寫入者",
      "tag": "in-progress",
      "step": "02"
    },
    {
      "id": "verifying",
      "type": "decision",
      "label": "驗證",
      "sublabel": "focused、gates",
      "tag": "候選 commit",
      "step": "03"
    },
    {
      "id": "merging",
      "type": "active",
      "label": "合入",
      "sublabel": "merge-into-integration",
      "tag": "結案 n",
      "step": "04"
    },
    {
      "id": "pushed",
      "type": "waiting",
      "label": "等 push",
      "sublabel": "PUSH_REQUIRED",
      "tag": "Operator",
      "step": "05"
    },
    {
      "id": "removed",
      "type": "success",
      "label": "已移除",
      "sublabel": "連同分支刪除",
      "tag": "completed",
      "step": "06"
    },
    {
      "id": "busy",
      "type": "waiting",
      "label": "排隊中",
      "sublabel": "exit 75 INTEGRATION_BUSY",
      "tag": "lock"
    },
    {
      "id": "pristine",
      "type": "neutral",
      "label": "PRISTINE",
      "sublabel": "從未 commit",
      "tag": "worktree-audit"
    },
    {
      "id": "kept",
      "type": "neutral",
      "label": "KEEP",
      "sublabel": "未合入的 wontfix／關閉 Issue",
      "tag": "需人判斷"
    }
  ],
  "transitions": [
    {
      "id": "w1",
      "from": "created",
      "to": "implementing",
      "label": "commit"
    },
    {
      "id": "w2",
      "from": "implementing",
      "to": "verifying",
      "label": "候選"
    },
    {
      "id": "w3",
      "from": "verifying",
      "to": "merging",
      "label": "結案 n",
      "variant": "emphasis"
    },
    {
      "id": "w4",
      "from": "merging",
      "to": "pushed",
      "label": "檢查通過"
    },
    {
      "id": "w5",
      "from": "pushed",
      "to": "removed",
      "label": "push 後",
      "variant": "emphasis"
    },
    {
      "id": "w6",
      "from": "verifying",
      "to": "implementing",
      "label": "gates 失敗",
      "variant": "security"
    },
    {
      "id": "w7",
      "from": "merging",
      "to": "busy",
      "label": "lock 忙碌",
      "variant": "dashed"
    },
    {
      "id": "w8",
      "from": "busy",
      "to": "merging",
      "label": "lock 釋放"
    },
    {
      "id": "w9",
      "from": "created",
      "to": "pristine",
      "label": "未開工",
      "variant": "dashed"
    },
    {
      "id": "w10",
      "from": "pristine",
      "to": "removed",
      "label": "audit 清理"
    },
    {
      "id": "w11",
      "from": "implementing",
      "to": "kept",
      "label": "wontfix",
      "variant": "dashed"
    },
    {
      "id": "w12",
      "from": "kept",
      "to": "removed",
      "label": "人判斷後清理"
    }
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "何時建、何時刪",
      "items": [
        "建：/issue-run 認領或「開工 n」把 label 設成 in-progress 時，不在開單或分級時",
        "刪：close-issue.mjs 第二次「結案」時；其他情況跑 worktree-audit.mjs 判定",
        "主路徑：建立 → 第一個 commit → deliver-candidate 產候選 → 結案 n 合入 → check-before-push 通過停在 PUSH_REQUIRED → ! git push → 再結案 n 移除"
      ]
    },
    {
      "dot": "amber",
      "title": "守則",
      "items": [
        "一個 worktree 同時只有一個寫入者",
        "分支從整合分支開出，不從 develop",
        "沒有 Orca 連結的 worktree 只給 isolated runner 等工具用途"
      ]
    },
    {
      "dot": "rose",
      "title": "Orca 的坑",
      "items": [
        "create／rm 可能回 runtime_unavailable 但實際成功：以 git worktree list 為準，絕不重試",
        "增量 worktree 以 --parent-worktree 掛在任務 worktree 下，合入後即刪"
      ]
    }
  ]
}
