{
  "schema_version": 2,
  "diagram_type": "workflow",
  "meta": {
    "title": "單張 Issue 交付主流程",
    "locale": "zh-TW",
    "quality_profile": "showcase",
    "output": "docs/workflow/diagrams/02-main-flow.html"
  },
  "lanes": [
    {
      "id": "operator",
      "label": "Operator（人）"
    },
    {
      "id": "claude",
      "label": "Claude Code"
    },
    {
      "id": "gitlab",
      "label": "GitLab"
    },
    {
      "id": "local",
      "label": "本機（worktree／Docker／hooks）"
    }
  ],
  "phases": [
    {
      "id": "intake",
      "label": "需求開單",
      "fromCol": 0,
      "toCol": 1
    },
    {
      "id": "build",
      "label": "worktree 內實作與驗證",
      "fromCol": 2,
      "toCol": 3,
      "variant": "emphasis"
    },
    {
      "id": "deliver",
      "label": "gates、合入、推送、結案",
      "fromCol": 4,
      "toCol": 5,
      "variant": "dashed"
    }
  ],
  "mainPath": [
    "req",
    "create",
    "queue",
    "run",
    "impl",
    "verify",
    "gates",
    "close1",
    "push",
    "close2"
  ],
  "nodes": [
    {
      "id": "req",
      "lane": "operator",
      "col": 0,
      "type": "external",
      "label": "需求討論",
      "sublabel": "口頭／spec／bug 回報"
    },
    {
      "id": "push",
      "lane": "gitlab",
      "col": 4,
      "type": "cloud",
      "label": "push-pinned.sh",
      "sublabel": "agent 推送已驗收 SHA",
      "tag": "無權限才交人"
    },
    {
      "id": "create",
      "lane": "claude",
      "col": 0,
      "type": "backend",
      "label": "issue-create.mjs",
      "sublabel": "唯一開單入口"
    },
    {
      "id": "queue",
      "lane": "claude",
      "col": 1,
      "type": "backend",
      "label": "/issue-queue",
      "sublabel": "分級與釐清"
    },
    {
      "id": "run",
      "lane": "claude",
      "col": 2,
      "type": "backend",
      "label": "/issue-run n",
      "sublabel": "認領 → in-progress",
      "tag": "此時才建 worktree"
    },
    {
      "id": "impl",
      "lane": "claude",
      "col": 3,
      "type": "backend",
      "label": "實作",
      "sublabel": "tdd／implement／code-review"
    },
    {
      "id": "close1",
      "lane": "claude",
      "col": 4,
      "type": "backend",
      "label": "「結案 n」",
      "sublabel": "close-issue.mjs 合入整合分支",
      "tag": "停在 PUSH_REQUIRED"
    },
    {
      "id": "close2",
      "lane": "claude",
      "col": 5,
      "type": "backend",
      "label": "推送後重跑結案",
      "sublabel": "留言、關單、刪 worktree"
    },
    {
      "id": "issue",
      "lane": "gitlab",
      "col": 0,
      "type": "cloud",
      "label": "Issue",
      "sublabel": "needs-triage"
    },
    {
      "id": "ready",
      "lane": "gitlab",
      "col": 1,
      "type": "cloud",
      "label": "Issue",
      "sublabel": "ready-for-agent"
    },
    {
      "id": "inprog",
      "lane": "gitlab",
      "col": 2,
      "type": "cloud",
      "label": "Issue",
      "sublabel": "in-progress"
    },
    {
      "id": "done",
      "lane": "gitlab",
      "col": 5,
      "type": "cloud",
      "label": "Issue",
      "sublabel": "completed，已關閉"
    },
    {
      "id": "wt",
      "lane": "local",
      "col": 2,
      "type": "database",
      "label": "Issue worktree",
      "sublabel": "feature-ron-issue-n"
    },
    {
      "id": "verify",
      "lane": "local",
      "col": 3,
      "type": "backend",
      "label": "focused 驗證",
      "sublabel": "compile／測試／run-docker-tests.sh"
    },
    {
      "id": "gates",
      "lane": "local",
      "col": 4,
      "type": "security",
      "label": "check-* gates",
      "sublabel": "SQL impact、pinned sources、Codex review"
    },
    {
      "id": "integ",
      "lane": "local",
      "col": 5,
      "type": "database",
      "label": "整合分支",
      "sublabel": "merge-into-integration.sh，有 lock"
    }
  ],
  "edges": [
    {
      "id": "req-create",
      "from": "req",
      "to": "create",
      "label": "確認範圍與驗收",
      "variant": "default"
    },
    {
      "id": "create-issue",
      "from": "create",
      "to": "issue",
      "label": "建立",
      "variant": "default",
      "role": "branch"
    },
    {
      "id": "create-queue",
      "from": "create",
      "to": "queue",
      "variant": "emphasis"
    },
    {
      "id": "queue-ready",
      "from": "queue",
      "to": "ready",
      "label": "設 label",
      "variant": "default",
      "role": "branch"
    },
    {
      "id": "queue-run",
      "from": "queue",
      "to": "run",
      "variant": "emphasis"
    },
    {
      "id": "run-inprog",
      "from": "run",
      "to": "inprog",
      "label": "issue-state --set",
      "variant": "default",
      "role": "branch"
    },
    {
      "id": "run-wt",
      "from": "run",
      "to": "wt",
      "label": "orca-worktree-create",
      "variant": "dashed",
      "role": "branch"
    },
    {
      "id": "run-impl",
      "from": "run",
      "to": "impl",
      "variant": "emphasis"
    },
    {
      "id": "impl-verify",
      "from": "impl",
      "to": "verify",
      "label": "只跑本單測試",
      "variant": "emphasis"
    },
    {
      "id": "verify-gates",
      "from": "verify",
      "to": "gates",
      "variant": "emphasis"
    },
    {
      "id": "gates-impl",
      "from": "gates",
      "to": "impl",
      "label": "未通過則修正",
      "variant": "security",
      "role": "error"
    },
    {
      "id": "gates-close1",
      "from": "gates",
      "to": "close1",
      "label": "候選 commit",
      "variant": "emphasis"
    },
    {
      "id": "close1-integ",
      "from": "close1",
      "to": "integ",
      "label": "合入並跑 check-before-push",
      "variant": "default",
      "role": "branch"
    },
    {
      "id": "close1-push",
      "from": "close1",
      "to": "push",
      "variant": "security",
      "role": "main"
    },
    {
      "id": "push-close2",
      "from": "push",
      "to": "close2",
      "label": "推送完成",
      "variant": "emphasis"
    },
    {
      "id": "close2-done",
      "from": "close2",
      "to": "done",
      "label": "completed",
      "variant": "default",
      "role": "branch"
    }
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "人只做三件事",
      "items": [
        "確認需求與驗收條件",
        "回答釐清問題、做產品決策",
        "沒有推送權限時才 ! git push"
      ]
    },
    {
      "dot": "emerald",
      "title": "Claude 的邊界",
      "items": [
        "所有 GitLab 寫入都走 scripts/，不用 glab 直接改",
        "worktree 在認領時才建立，一個 worktree 同時只有一個寫入者",
        "合入整合分支只能用 merge-into-integration.sh"
      ]
    },
    {
      "dot": "rose",
      "title": "停點",
      "items": [
        "gates 未通過回到實作，最多兩輪重審",
        "PUSH_REQUIRED 是停點：agent 以 push-pinned.sh 推送後立即重跑結案"
      ]
    }
  ]
}
