// Construction / setup-phase diagram
// Compile: dot -Tpdf migrate-construct.dot -o migrate-construct-dot.pdf
//      or: dot -Tsvg migrate-construct.dot -o migrate-construct-dot.svg

digraph migrate_construct {

    // ── Global defaults ──────────────────────────────────────────────────
    graph [
        rankdir  = TB
        fontname = "Helvetica"
        fontsize = 11
        splines  = spline
        nodesep  = 0.8
        ranksep  = 0.9
        bgcolor  = "white"
    ]
    node [
        fontname = "Helvetica"
        fontsize = 10
        style    = "filled,rounded"
        shape    = box
        penwidth = 1.2
        margin   = "0.18,0.10"
    ]
    edge [
        fontname = "Helvetica"
        fontsize = 8
        color    = "#444444"
        penwidth = 1.0
    ]

    // ── Actors ───────────────────────────────────────────────────────────
    Human [
        shape     = ellipse
        fillcolor = "#b3d9ff"
        label     = "Human"
    ]
    LLM [
        shape     = ellipse
        fillcolor = "#ffccbc"
        label     = "Sonnet 4.6"
    ]

    // ── Inputs studied during construction ───────────────────────────────
    Tests [
        fillcolor = "#fff9c4"
        label     = "test_*.cxx\n(83 files)"
    ]
    Refs [
        fillcolor = "#e0e0e0"
        label     = "References\ndoctest_binning.cxx · Testing.h\nbd  ·  claude CLI"
    ]

    // ── Survey outputs ───────────────────────────────────────────────────
    UtilTests [
        fillcolor = "#c8e6c9"
        label     = "util-tests.txt\n(40 files to migrate)"
    ]
    UtilChecks [
        fillcolor = "#fffacd"
        label     = "util-checks.txt\n(45 files to rename)"
    ]

    // ── Beads DB ─────────────────────────────────────────────────────────
    Beads [
        shape     = cylinder
        fillcolor = "#c8e6c9"
        label     = "Beads DB\nwct-0jr  migration (40 tasks)\nwct-4b1  post-migration"
        height    = 1.1
    ]

    // ── Migration artifacts ───────────────────────────────────────────────
    Skill [
        fillcolor = "#fffacd"
        style     = "filled,rounded,dashed"
        penwidth  = 1.8
        label     = "migrate-test.md\n(skill / command)"
    ]
    Script [
        fillcolor = "#fffacd"
        label     = "run-migrate.fish"
    ]

    // ── Handoff ───────────────────────────────────────────────────────────
    Ready [
        fillcolor = "#a5d6a7"
        penwidth  = 2.0
        label     = "Ready to run\n(see migrate-arch.dot)"
    ]

    // ── Rank constraints (rows in TB layout) ─────────────────────────────
    { rank = same;  Human;     LLM           }   // row 1
    { rank = same;  Tests;     Refs          }   // row 2
    { rank = same;  UtilTests; UtilChecks    }   // row 3
    { rank = same;  Beads;     Skill; Script }   // row 4
    // Ready alone in row 5

    // Invisible left-to-right ordering within ranks
    Human     -> LLM        [ style = invis ]
    Tests     -> Refs       [ style = invis ]
    UtilTests -> UtilChecks [ style = invis ]
    Beads     -> Skill      [ style = invis ]
    Skill     -> Script     [ style = invis ]

    // ── Visible edges ────────────────────────────────────────────────────

    // LLM surveys all test files; both actors study references
    LLM   -> Tests [ label = "surveys" weight = 4 ]
    LLM   -> Refs  [ label      = "studies"
                     constraint = true
                     weight     = 1 ]
    Human -> Refs  [ label      = "provides\ncontext"
                     constraint = true
                     weight     = 1 ]

    // Survey produces the two classification lists
    Tests -> UtilTests  [ label = "classify\n→ migrate" weight = 3 ]
    Tests -> UtilChecks [ label = "classify\n→ rename"  weight = 3 ]

    // References inform artifact writing (dashed; no layout force)
    Refs -> Skill  [ label      = "informs"
                     style      = dashed
                     constraint = true
                     weight     = 1 ]
    Refs -> Script [ label      = "informs"
                     style      = dashed
                     constraint = true
                     weight     = 1 ]

    // util-tests.txt drives the Beads task-creation bash loop
    UtilTests -> Beads [ label = "bash loop\nbd create task" weight = 3 ]

    // LLM also creates the two epics directly
    LLM -> Beads [ label      = "bd create\nepics"
                   style      = dashed
                   constraint = false
                   weight     = 1 ]

    // Both actors collaborate on the migration skill
    LLM   -> Skill  [ label      = "writes"
                      constraint = true
                      weight     = 2 ]
    Human -> Skill  [ label      = "co-writes\n& edits"
                      constraint = true
                      weight     = 4 ]

    // LLM writes the driver script; Human reviews and edits it
    LLM   -> Script [ label      = "writes"
                      constraint = true
                      weight     = 2 ]
    Human -> Script [ label      = "reviews\n& edits"
                      constraint = true
                      weight     = 1 ]

    // All three outputs converge on "ready to run"
    Skill  -> Ready [ weight = 3 ]
    Script -> Ready [ weight = 3 ]
    Beads  -> Ready [ label      = "tasks ready"
                      style      = dashed
                      weight     = 1 ]
}
