package tui import ( "fmt" "os/exec" "git.a-wan.net/alan/pipelines/internal/runinspect" tea "github.com/charmbracelet/bubbletea" ) type debugClosedMsg struct{ err error } func (m Model) selectedRunID() int64 { if !m.runOpen || m.runStartRequest != "" { return 0 } if m.runDetail != nil { return m.runDetail.ID } if m.requestedRunID > 0 { return 0 } runs := m.visibleRuns() if len(runs) > 0 { return runs[min(m.runIndex, len(runs)-1)].ID } return 0 } func (m Model) debugRun() (tea.Model, tea.Cmd) { id := m.selectedRunID() if id <= 0 { m.appendLine("Select a loaded run to debug.") return m, nil } m.editorDebugRunID = id m.editorOpen = true m.editorIndex = 0 m.editorInput = newInput() m.editorInput.Placeholder = "Search configured harnesses or nvim…" m.editorDraft = nil return m, m.editorInput.Focus() } func (m Model) debugUsing(id int64, choice string) (tea.Model, tea.Cmd) { cli, err := runinspect.CLIExecutable() if err != nil { m.appendLine("debug: pipelines CLI is unavailable: " + err.Error()) return m, nil } cmd := exec.Command(cli, "--url", m.url, "debug", fmt.Sprint(id), "--harness", choice, "--yes") return m.confirmMutation(fmt.Sprintf("Open a new debugging session for run #%d?", id), func() tea.Cmd { return tea.ExecProcess(cmd, func(err error) tea.Msg { return debugClosedMsg{err} }) }) }