Add shared live run graphs, debugging, editor choice and draft cleanup

This commit is contained in:
2026-10-09 19:17:43 +01:00
parent 9b8afc874f
commit 0f80ff4e95
33 changed files with 1162 additions and 72 deletions
+15 -1
View File
@@ -15,6 +15,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/draft"
"git.a-wan.net/alan/pipelines/internal/opencode"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/runinspect"
)
type editedMsg struct {
@@ -43,6 +44,10 @@ func editDraft(name, source string, confirm ...bool) tea.Cmd {
}
func editDraftMode(name, source string, needsConfirm, fresh bool, metadata ...draft.Draft) tea.Cmd {
return editDraftUsing("", name, source, needsConfirm, fresh, metadata...)
}
func editDraftUsing(choice, name, source string, needsConfirm, fresh bool, metadata ...draft.Draft) tea.Cmd {
var meta draft.Draft
if len(metadata) > 0 {
meta = metadata[0]
@@ -57,7 +62,9 @@ func editDraftMode(name, source string, needsConfirm, fresh bool, metadata ...dr
return func() tea.Msg { return editedMsg{name: name, path: path, err: err} }
}
var command *exec.Cmd
if name != "" && (strings.TrimSpace(os.Getenv("VISUAL")) != "" || strings.TrimSpace(os.Getenv("EDITOR")) != "") {
if choice == "nvim" {
command = exec.Command("nvim", path)
} else if choice == "" && name != "" && (strings.TrimSpace(os.Getenv("VISUAL")) != "" || strings.TrimSpace(os.Getenv("EDITOR")) != "") {
editor, args, editorErr := draftEditor()
if editorErr != nil {
return func() tea.Msg { return editedMsg{name: name, path: path, err: editorErr} }
@@ -68,6 +75,13 @@ func editDraftMode(name, source string, needsConfirm, fresh bool, metadata ...dr
if exeErr != nil {
return func() tea.Msg { return editedMsg{name: name, path: path, err: exeErr} }
}
if cli, lookupErr := runinspect.CLIExecutable(); lookupErr == nil {
executable = cli
} else if choice == "opencode" {
return func() tea.Msg {
return editedMsg{name: name, path: path, err: fmt.Errorf("pipelines CLI is required for OpenCode editing: %w", lookupErr)}
}
}
cli := quoteCLI(executable) + " --url " + quoteCLI(meta.Server)
command, err = author.Command(context.Background(), opencode.Executable(), d, "", cli)
if err != nil {
+10 -2
View File
@@ -13,7 +13,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
)
var commands = []string{":logs", ":new", ":drafts", ":templates", ":refresh", ":ping", ":edit", ":submit", ":versions", ":run", ":runs", ":retry", ":pipeline", ":home", ":quit"}
var commands = []string{":logs", ":new", ":drafts", ":templates", ":refresh", ":ping", ":edit", ":submit", ":versions", ":run", ":runs", ":retry", ":debug", ":pipeline", ":home", ":quit"}
func (m Model) footerContent() string {
label := fmt.Sprintf(" LOGS %d · :logs ", len(m.lines))
@@ -31,7 +31,9 @@ func (m Model) footerContent() string {
available := m.width - lipgloss.Width(label) - 1
left := ""
if available > 0 {
left = ansi.Truncate(m.help.View(m.keys), available, "…")
keys := m.keys
keys.retryAvailable = m.selectedFailedRun() > 0
left = ansi.Truncate(m.help.View(keys), available, "…")
}
return left + strings.Repeat(" ", max(0, m.width-lipgloss.Width(left)-lipgloss.Width(label))) + label
}
@@ -83,6 +85,10 @@ func (m Model) pageCommands() []string {
detailPage := m.keys.detail && !m.runOpen
for _, command := range commands {
switch command {
case ":debug":
if m.selectedRunID() <= 0 {
continue
}
case ":retry":
if m.selectedFailedRun() <= 0 {
continue
@@ -150,6 +156,8 @@ func (m Model) updatePalette(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.paletteOpen = false
m.keys.palette = false
switch command {
case ":debug":
return m.debugRun()
case ":retry":
return m.retrySelectedRun()
case ":pipeline":
+43
View File
@@ -0,0 +1,43 @@
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
}
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))
return m, tea.ExecProcess(cmd, func(err error) tea.Msg { return debugClosedMsg{err} })
}
+33
View File
@@ -0,0 +1,33 @@
package tui
import (
"context"
"os"
"path/filepath"
"slices"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
)
func TestRunDebugActionAvailableForRunningAndFinishedRuns(t *testing.T) {
bin := t.TempDir()
os.WriteFile(filepath.Join(bin, "pipelines"), []byte("#!/bin/sh\nexit 0\n"), 0700)
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
for _, status := range []string{"running", "failed", "succeeded", "canceled"} {
m := New(context.Background(), "ws://example/connect")
m.runOpen = true
m.keys.runs = true
m.requestedRunID = 7
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 7, Status: status}}
if !slices.Contains(m.pageCommands(), ":debug") {
t.Fatal("debug unavailable", status)
}
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'D'}})
m = updated.(Model)
if cmd == nil || m.runDetail.ID != 7 || m.runStartRequest != "" || m.runDetail.Status != status {
t.Fatal("debug changed or retried run", status)
}
}
}
+36 -1
View File
@@ -19,6 +19,7 @@ type draftValidationMsg struct {
}
func (m Model) openDrafts() (tea.Model, tea.Cmd) {
m.draftDeletingPath = ""
m.draftOpen = true
m.keys.drafts = true
m.draftIndex = 0
@@ -66,7 +67,38 @@ func (m Model) selectedDraft() (draft.Draft, string, error) {
}
func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.draftDeletingPath != "" {
switch msg.String() {
case "esc", "n":
m.draftDeletingPath = ""
return m, nil
case "y":
path := m.draftDeletingPath
m.draftDeletingPath = ""
if m.submitID != "" {
m.draftError = "Wait for submission to finish before deleting drafts."
return m, nil
}
if err := draft.Delete(path); err != nil {
m.draftError = err.Error()
return m, nil
}
if m.pendingDraft != nil && m.pendingDraft.path == path {
m.pendingDraft = nil
m.confirmOpen = false
m.keys.confirm = false
m.submitNotice = ""
}
return m.openDrafts()
}
return m, nil
}
switch msg.String() {
case "x":
if len(m.draftItems) > 0 && m.submitID == "" {
m.draftDeletingPath = m.draftItems[m.draftIndex].Path
}
return m, nil
case "esc":
m.draftOpen = false
m.keys.drafts = false
@@ -122,6 +154,9 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
func (m Model) draftsView(height int) string {
if m.draftDeletingPath != "" {
return popup(m.width, height, 90, []string{"Delete retained draft?", m.draftDeletingPath, "Only this draft and its metadata are deleted. Published pipelines/history stay intact.", "y delete · n/Esc keep"})
}
if len(m.draftItems) == 0 {
return fitBlock([]string{"Drafts", "No retained drafts.", m.draftError, "r refresh · Esc back"}, m.width, height)
}
@@ -135,7 +170,7 @@ func (m Model) draftsView(height int) string {
rows := max(0, height-len(lines)-1)
top := min(m.draftTop, max(0, len(source)-rows))
lines = append(lines, source[top:min(len(source), top+rows)]...)
lines = append(lines, "n/p select · e edit · v validate · s submit · r refresh · Esc back")
lines = append(lines, "n/p select · e edit · v validate · s submit · x delete · r refresh · Esc back")
for i := range lines {
lines[i] = ansi.Strip(lines[i])
}
+68
View File
@@ -0,0 +1,68 @@
package tui
import (
"strings"
"git.a-wan.net/alan/pipelines/internal/draft"
tea "github.com/charmbracelet/bubbletea"
"github.com/sahilm/fuzzy"
)
func (m Model) editorChoices() []string {
choices := []string{"nvim", "OpenCode"}
if query := strings.TrimSpace(m.editorInput.Value()); query != "" {
var result []string
for _, match := range fuzzy.Find(query, choices) {
result = append(result, match.Str)
}
return result
}
return choices
}
func (m Model) updateEditorPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
choices := m.editorChoices()
switch msg.String() {
case "esc":
m.editorOpen = false
m.editorDraft = nil
return m, nil
case "tab", "down", "ctrl+n":
if len(choices) > 0 {
m.editorIndex = (m.editorIndex + 1) % len(choices)
}
return m, nil
case "shift+tab", "up", "ctrl+p":
if len(choices) > 0 {
m.editorIndex = (m.editorIndex + len(choices) - 1) % len(choices)
}
return m, nil
case "enter":
if len(choices) == 0 || m.editorDraft == nil {
return m, nil
}
choice := strings.ToLower(choices[min(m.editorIndex, len(choices)-1)])
d := m.editorDraft
m.editorOpen = false
m.editorDraft = nil
return m, editDraftUsing(choice, d.name, d.source, true, false, draft.Draft{Server: m.url, BaseVersion: d.baseVersion})
}
var cmd tea.Cmd
m.editorInput, cmd = m.editorInput.Update(msg)
m.editorIndex = 0
return m, cmd
}
func (m Model) editorPickerView(height int) string {
input := m.editorInput
input.Width = max(1, min(60, m.width-12))
lines := []string{"Edit pipeline with…", input.View(), "Tab/Shift+Tab choose · type to search · Enter open · Esc cancel", ""}
choices := m.editorChoices()
for i, choice := range choices {
lines = append(lines, menuOption(choice, i == m.editorIndex))
}
if len(choices) == 0 {
lines = append(lines, "No matching editor.")
}
return popup(m.width, height, 80, lines)
}
+93
View File
@@ -0,0 +1,93 @@
package tui
import (
"context"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/draft"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
)
func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testing.T) {
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
m := New(context.Background(), "ws://example/connect")
m.width = 120
m.height = 35
m.keys.detail = true
source := pipeline.Template([]string{"one"}, true)
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{Name: "workflow", Version: 2}, LatestVersion: 4, Source: source}
updated, _ := m.editPipeline()
m = updated.(Model)
if !m.editorOpen || m.editorDraft.baseVersion != 4 || m.editorDraft.source != pipeline.ExecutionSource(source) {
t.Fatal("edit did not ask which editor or lost version guard")
}
if items, _ := draft.List(); len(items) != 0 {
t.Fatal("opening/canceling picker should not create a draft")
}
if view := ansi.Strip(m.editorPickerView(30)); !strings.Contains(view, "nvim") || !strings.Contains(view, "OpenCode") {
t.Fatal("editor options missing", view)
}
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab})
m = updated.(Model)
if m.editorIndex != 1 {
t.Fatal("Tab did not select OpenCode")
}
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyShiftTab})
m = updated.(Model)
if m.editorIndex != 0 {
t.Fatal("Shift+Tab did not select nvim")
}
m.editorInput.SetValue("ocd")
if choices := m.editorChoices(); len(choices) != 1 || choices[0] != "OpenCode" {
t.Fatal("fuzzy editor search failed", choices)
}
m.editorInput.SetValue("nv")
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if cmd == nil || m.editorOpen {
t.Fatal("editor selection did not launch")
}
items, err := draft.List()
if err != nil || len(items) != 1 || items[0].BaseVersion != 4 || items[0].Server != m.url {
t.Fatal("edit did not retain guarded draft", items, err)
}
if m.confirmOpen || m.submitID != "" {
t.Fatal("editor selection bypassed explicit submission")
}
}
func TestDraftCleanupRequiresConfirmationAndPreservesOtherDraft(t *testing.T) {
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
a, _ := draft.Create("discard", "discard", "server", true, 0)
b, _ := draft.Create("keep", "keep", "server", true, 0)
m := New(context.Background(), "server")
updated, _ := m.openDrafts()
m = updated.(Model)
for i, d := range m.draftItems {
if d.Path == a.Path {
m.draftIndex = i
}
}
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
m = updated.(Model)
if m.draftDeletingPath != a.Path {
t.Fatal("delete confirmation not opened")
}
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyEsc})
m = updated.(Model)
if _, err := draft.Read(a.Path); err != nil {
t.Fatal("cancel deleted draft", err)
}
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
m = updated.(Model)
m.pendingDraft = &editedMsg{path: a.Path}
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
m = updated.(Model)
if m.pendingDraft != nil || m.draftDeletingPath != "" || len(m.draftItems) != 1 || m.draftItems[0].Path != b.Path {
t.Fatal("cleanup did not clear selected draft/refresh browser")
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ func TestHomeShortcutOpensFailedRunsAndDisplaysHintInBothPanels(t *testing.T) {
m = updated.(Model)
m.width = 120
m.height = 40
m.runs = []protocol.RunSummary{{ID: 1, Status: "succeeded", Name: "passed"}, {ID: 2, Status: "failed", Name: "broken"}, {ID: 3, Status: "running", Name: "active"}, {ID: 4, Status: "canceled", Name: "canceled"}, {ID: 5, Status: "failed", Name: "also broken"}}
m.runs = []protocol.RunSummary{{ID: 1, Status: "succeeded", Name: "passed"}, {ID: 2, Status: "failed", Name: "broken", FinishedAt: "2026-10-09T00:00:00Z"}, {ID: 3, Status: "running", Name: "active"}, {ID: 4, Status: "canceled", Name: "canceled"}, {ID: 5, Status: "failed", Name: "also broken", FinishedAt: "2026-10-09T00:00:00Z"}}
view := ansi.Strip(strings.Join(m.homeLines(), "\n"))
if strings.Count(view, "r failed runs") != 2 {
t.Fatal("missing shortcut in both panels", view)
+40 -16
View File
@@ -38,21 +38,22 @@ type socketMsg struct {
type reconnectMsg struct{}
type keyMap struct {
ping key.Binding
quit key.Binding
create key.Binding
enter key.Binding
cancel key.Binding
commands key.Binding
logs bool
palette bool
search key.Binding
detail bool
versions bool
confirm bool
runs bool
templates bool
drafts bool
ping key.Binding
quit key.Binding
create key.Binding
enter key.Binding
cancel key.Binding
commands key.Binding
logs bool
palette bool
search key.Binding
detail bool
versions bool
confirm bool
runs bool
retryAvailable bool
templates bool
drafts bool
}
func (k keyMap) ShortHelp() []key.Binding {
@@ -75,7 +76,11 @@ func (k keyMap) ShortHelp() []key.Binding {
return []key.Binding{key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "template")), key.NewBinding(key.WithKeys("v"), key.WithHelp("v", "render/source")), key.NewBinding(key.WithKeys("enter"), key.WithHelp("Enter", "use template")), k.cancel}
}
if k.runs {
return []key.Binding{k.commands, key.NewBinding(key.WithKeys("p"), key.WithHelp("p", "pipeline")), key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "retry failed")), key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "select/scroll")), key.NewBinding(key.WithKeys("pgup", "pgdown"), key.WithHelp("PgUp/Dn", "page")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("Esc", "back"))}
bindings := []key.Binding{k.commands, key.NewBinding(key.WithKeys("g"), key.WithHelp("g", "graph")), key.NewBinding(key.WithKeys("D"), key.WithHelp("D", "debug")), key.NewBinding(key.WithKeys("p"), key.WithHelp("p", "pipeline"))}
if k.retryAvailable {
bindings = append(bindings, key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "retry failed")))
}
return append(bindings, key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "select/scroll")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("Esc", "back")))
}
if k.detail {
return []key.Binding{k.commands, k.search, key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "next/prev stage")), key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "runs")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "scroll")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "home"))}
@@ -151,6 +156,14 @@ type Model struct {
runError string
runPipelineID int64
runFailedOnly bool
runGraphFocus bool
runGraphTop int
runGraphPan int
editorOpen bool
editorInput textinput.Model
editorIndex int
editorDraft *editedMsg
draftDeletingPath string
runSpinner spinner.Model
templates []protocol.Template
templateOpen, templateRaw bool
@@ -210,6 +223,11 @@ func (m Model) read() tea.Cmd {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case debugClosedMsg:
if msg.err != nil {
m.appendLine("OpenCode debug: " + msg.err.Error())
}
return m, nil
case spinner.TickMsg:
var cmd tea.Cmd
m.runSpinner, cmd = m.runSpinner.Update(msg)
@@ -436,6 +454,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.String() == "ctrl+c" {
return m, tea.Quit
}
if m.editorOpen {
return m.updateEditorPicker(msg)
}
if m.logOpen {
return m.updateLogs(msg)
}
@@ -649,6 +670,9 @@ func (m Model) View() string {
} else if m.confirmOpen {
content = m.confirmView(bodyHeight)
}
if m.editorOpen {
content = m.editorPickerView(bodyHeight)
}
parts = append(parts, content)
}
return strings.Join(append(parts, footer), "\n")
+16 -13
View File
@@ -177,38 +177,41 @@ func (m Model) graphLines() []string {
}
func (m Model) graphPanel(width, height int) string {
label := "Graph"
if !m.stageFocus {
label = "▸ " + label
}
return graphViewport(label, m.graphLines(), width, height, m.pipelineTop, m.graphPan, !m.stageFocus, "Tab pane · r runs · * fallback error")
}
// Shared graph viewport for definitions and executed run paths.
func graphViewport(label string, lines []string, width, height, scrollTop, pan int, focused bool, footer string) string {
if width <= 0 || height <= 0 {
return ""
}
inner := max(1, width-4)
rows := max(0, height-5)
lines := m.graphLines()
top := max(0, min(m.pipelineTop, max(0, len(lines)-rows)))
top := max(0, min(scrollTop, max(0, len(lines)-rows)))
end := min(len(lines), top+rows)
body := make([]string, 0, end-top)
for _, line := range lines[top:end] {
body = append(body, ansi.Cut(line, m.graphPan, m.graphPan+inner))
body = append(body, ansi.Cut(line, pan, pan+inner))
}
graphWidth := 0
for _, line := range lines {
graphWidth = max(graphWidth, ansi.StringWidth(line))
}
label := "Graph"
if !m.stageFocus {
label = "▸ " + label
}
if m.graphPan > 0 {
if pan > 0 {
label = "← " + label
}
if m.graphPan+inner < graphWidth {
if pan+inner < graphWidth {
label += " →"
}
headers := []string{bar(label, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, !m.stageFocus), lipgloss.NewStyle().Foreground(themeMuted).Render(strings.Repeat("─", inner))}
footer := "Tab pane · r runs · * fallback error"
headers := []string{bar(label, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, focused), lipgloss.NewStyle().Foreground(themeMuted).Render(strings.Repeat("─", inner))}
if graphWidth > inner {
footer = "←/→ pan · Tab pane · * fallback error"
footer = "←/→ pan · " + footer
}
return panel(width, height, headers, body, footer, !m.stageFocus)
return panel(width, height, headers, body, footer, focused)
}
func (m Model) stageTabs(width int) string {
+7 -1
View File
@@ -194,7 +194,13 @@ func (m Model) editPipeline() (tea.Model, tea.Cmd) {
m.appendLine("submission already in progress")
return m, nil
}
return m, editDraftMode(m.detail.Name, pipeline.ExecutionSource(m.detail.Source), true, false, draft.Draft{Server: m.url, BaseVersion: m.detail.LatestVersion})
m.editorOpen = true
m.editorIndex = 0
m.editorInput = newInput()
m.editorInput.Placeholder = "Search nvim or OpenCode…"
m.editorInput.Focus()
m.editorDraft = &editedMsg{name: m.detail.Name, source: pipeline.ExecutionSource(m.detail.Source), baseVersion: m.detail.LatestVersion}
return m, m.editorInput.Focus()
}
func (m Model) updatePipeline(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
+1 -1
View File
@@ -90,7 +90,7 @@ func TestRetryResponseClearsPendingRequestAndAllowsAnotherFailedAttempt(t *testi
m.runOpen = true
m.keys.runs = true
m.runStartRequest = "run-2"
run := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 3, Status: "failed"}, RetryOf: 1, Input: map[string]any{"prompt": "task", "pwd": "/project"}}
run := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 3, Status: "failed", FinishedAt: "2026-10-09T00:00:00Z"}, RetryOf: 1, Input: map[string]any{"prompt": "task", "pwd": "/project"}}
updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.RunStarted, ID: "run-2", RunDetail: run}))
m = updated.(Model)
if m.runDetail != run || m.requestedRunID != 3 || m.runStartRequest != "" || m.selectedFailedRun() != 3 {
+67 -8
View File
@@ -19,7 +19,12 @@ func (m Model) selectedFailedRun() int64 {
return 0
}
if m.runDetail != nil {
if m.runDetail.Status == "failed" {
if m.runDetail.Status == "failed" && m.runDetail.FinishedAt != "" && !m.runDetail.Executing {
for _, step := range m.runDetail.Steps {
if step.AgentActive {
return 0
}
}
return m.runDetail.ID
}
return 0
@@ -30,7 +35,7 @@ func (m Model) selectedFailedRun() int64 {
runs := m.visibleRuns()
if len(runs) > 0 {
r := runs[min(m.runIndex, len(runs)-1)]
if r.Status == "failed" {
if r.Status == "failed" && r.FinishedAt != "" && !r.Executing {
return r.ID
}
}
@@ -89,6 +94,9 @@ func (m *Model) closeRuns() {
m.runDetailFocus = false
m.runPipelineID = 0
m.runFailedOnly = false
m.runGraphFocus = false
m.runGraphTop = 0
m.runGraphPan = 0
}
func (m Model) visibleRuns() []protocol.RunSummary {
@@ -152,9 +160,43 @@ func (m Model) runPageSize() int {
if m.runSidebarWidth() == 0 {
extra = 11
}
if m.runDetail != nil && m.height-4 >= 14 {
extra += (m.height - 4) / 2
}
return max(1, m.height-extra)
}
func (m Model) openOpenCodeEvidence() (tea.Model, tea.Cmd) {
if m.runDetail == nil {
return m, nil
}
index := -1
for i, step := range m.runDetail.Steps {
if step.SessionID != "" {
index = i
}
if step.AgentActive {
index = i
break
}
}
if index < 0 {
m.runError = "No retained OpenCode agent session for this run yet."
return m, nil
}
m.selectRunStep(index + 1)
m.runGraphFocus = false
m.runDetailFocus = true
m.runTop = 0
if m.runCollapsed == nil {
m.runCollapsed = map[string]bool{}
}
for section := 0; section < 5; section++ {
m.runCollapsed[m.runSectionKey(section)] = section != 3
}
return m, nil
}
func runStatus(status string) string {
color := themeMuted
switch status {
@@ -175,9 +217,12 @@ func runDuration(start, end string) string {
}
last, err := time.Parse(time.RFC3339, end)
if err != nil {
return "in progress"
if end != "" {
return "—"
}
last = time.Now()
}
return last.Sub(first).Round(time.Second).String()
return max(time.Duration(0), last.Sub(first)).Round(time.Second).String()
}
func valueLines(values map[string]any) []string {
@@ -366,7 +411,21 @@ func (m Model) runSelectionLabel() string {
return "Run overview"
}
func (m Model) runsView(height int) string {
func (m Model) runActions() string {
text := "p pipeline"
if m.selectedRunID() > 0 {
text += " · D debug"
}
if m.runDetail != nil {
text += " · a OpenCode evidence"
}
if m.selectedFailedRun() > 0 {
text += " · r retry failed"
}
return text
}
func (m Model) runsDetailsView(height int) string {
if m.runDetail == nil {
title := "Runs · Enter inspect · Esc close"
if m.runPipelineID > 0 && m.detail != nil {
@@ -395,12 +454,12 @@ func (m Model) runsView(height int) string {
if m.runError != "" {
rows = append(rows, m.runError)
}
return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, "j/k select · Enter inspect · p pipeline · r retry failed", true)
return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, "j/k select · Enter inspect · "+m.runActions(), true)
}
r := m.runDetail
header := bar(fmt.Sprintf("#%d %s · v%d", r.ID, r.Name, r.Version), m.progress(r.Status)+" · "+runDuration(r.CreatedAt, r.FinishedAt), m.width, false)
if height <= 6 {
return fitBlock([]string{header, m.runSelectionLabel(), "p pipeline · r retry failed · Tab pane · Esc back"}, m.width, height)
return fitBlock([]string{header, m.runSelectionLabel(), m.runActions() + " · Tab pane · Esc back"}, m.width, height)
}
innerHeight := height - 2
sidebar := m.runSidebarWidth()
@@ -440,7 +499,7 @@ func (m Model) runsView(height int) string {
lines := m.runSectionLines(max(1, rightWidth-4))
page := max(0, innerHeight-4)
top := max(0, min(m.runTop, max(0, len(lines)-page)))
footer := fmt.Sprintf("%d–%d / %d · s/i/o/t/m sections · p pipeline · r retry failed · PgUp/Dn · Esc back", min(top+1, len(lines)), min(top+page, len(lines)), len(lines))
footer := fmt.Sprintf("%d–%d / %d · s/i/o/t/m sections · %s · PgUp/Dn · Esc back", min(top+1, len(lines)), min(top+page, len(lines)), len(lines), m.runActions())
label := m.runSelectionLabel()
if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) {
label = fmt.Sprintf("Details · %s · step %d", r.Steps[m.runStepIndex-1].Stage, r.Steps[m.runStepIndex-1].Sequence)
+78
View File
@@ -0,0 +1,78 @@
package tui
import (
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// Each visit is a separate node, preserving cycles. Only recorded routes are drawn.
func (m Model) runPathGraph() protocol.Graph {
r := m.runDetail
if r == nil {
return protocol.Graph{}
}
graph := protocol.Graph{}
for i, step := range r.Steps {
node := protocol.Stage{Key: m.runVisitKey(i), Edges: map[string]string{}}
if step.Target != "" && step.Outcome != "" {
if protocol.IsTerminal(step.Target) {
node.Edges[step.Outcome] = step.Target
} else if i+1 < len(r.Steps) && r.Steps[i+1].Stage == step.Target {
node.Edges[step.Outcome] = m.runVisitKey(i + 1)
}
}
graph.Stages = append(graph.Stages, node)
}
return graph
}
func (m Model) runVisitKey(index int) string {
step := m.runDetail.Steps[index]
return fmt.Sprintf("%d. %s (%s)", step.Sequence, step.Stage, m.stepProgressStatus(step))
}
func (m Model) runGraphLines(_ int) []string {
graph := m.runPathGraph()
if len(graph.Stages) == 0 {
return []string{"Waiting for the first stage…"}
}
selected := graph.Stages[len(graph.Stages)-1].Key
if m.runStepIndex > 0 && m.runStepIndex <= len(graph.Stages) {
selected = graph.Stages[m.runStepIndex-1].Key
}
return renderGraph(graph, selected)
}
func (m Model) runsView(height int) string {
if m.runDetail == nil || height < 14 {
return m.runsDetailsView(height)
}
graphHeight := height / 2
top, pan := m.runGraphTop, m.runGraphPan
if !m.runGraphFocus {
top, pan = m.runGraphFollow()
}
graph := graphViewport("Run path · actual visits", m.runGraphLines(max(3, m.width-4)), m.width, graphHeight, top, pan, m.runGraphFocus, "g graph/details · arrows pan · j/k scroll · live")
details := m.runsDetailsView(height - graphHeight)
return fitBlock(strings.Split(graph+"\n"+details, "\n"), m.width, height)
}
func (m Model) runGraphFollow() (int, int) {
graph := m.runPathGraph()
if len(graph.Stages) == 0 {
return 0, 0
}
index := len(graph.Stages) - 1
if m.runStepIndex > 0 {
index = min(m.runStepIndex-1, index)
}
layout := layoutGraph(graph)
for _, node := range layout.nodes {
if node.key == graph.Stages[index].Key {
return node.y, max(0, node.x-(m.width-4-node.width)/2)
}
}
return 0, 0
}
+119
View File
@@ -0,0 +1,119 @@
package tui
import (
"context"
"strings"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func TestRunPathUsesSharedRendererAndRecordedRoutesWithRepeatedVisits(t *testing.T) {
m := New(context.Background(), "")
m.width = 120
m.height = 40
m.runOpen = true
m.keys.runs = true
m.requestedRunID = 1
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Status: "running", CreatedAt: time.Now().Add(-time.Minute).Format(time.RFC3339)}, Steps: []protocol.RunStep{
{Sequence: 1, Stage: "plan", Status: "completed", Outcome: "success", Target: "implement"},
{Sequence: 2, Stage: "implement", Status: "completed", Outcome: "revise", Target: "plan"},
{Sequence: 3, Stage: "plan", Status: "running", AgentActive: true},
}}
graph := m.runPathGraph()
if len(graph.Stages) != 3 || graph.Stages[0].Key == graph.Stages[2].Key || graph.Stages[0].Edges["success"] != graph.Stages[1].Key || graph.Stages[1].Edges["revise"] != graph.Stages[2].Key || len(graph.Stages[2].Edges) != 0 {
t.Fatal("run graph lost actual traversal or invented an edge", graph)
}
if got, want := strings.Join(m.runGraphLines(116), "\n"), strings.Join(renderGraph(graph, graph.Stages[2].Key), "\n"); got != want {
t.Fatal("run graph diverged from common renderer")
}
view := ansi.Strip(m.runsView(36))
if strings.Index(view, "Run path") < 0 || strings.Index(view, "Run path") > strings.Index(view, "Run overview") || !strings.Contains(view, "3. plan (running)") {
t.Fatal("run graph missing above details or current visit not visible", view)
}
refreshed := *m.runDetail
refreshed.Steps = append([]protocol.RunStep(nil), m.runDetail.Steps...)
refreshed.Status = "succeeded"
refreshed.FinishedAt = time.Now().Format(time.RFC3339)
refreshed.Steps[2].Status = "completed"
refreshed.Steps[2].AgentActive = false
refreshed.Steps[2].Outcome = "success"
refreshed.Steps[2].Target = protocol.SuccessEnd
updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: &refreshed}))
m = updated.(Model)
graph = m.runPathGraph()
if graph.Stages[2].Edges["success"] != protocol.SuccessEnd || strings.Contains(graph.Stages[2].Key, "running") {
t.Fatal("poll response did not refresh run graph", graph)
}
m = runKey(m, "g")
if !m.runGraphFocus {
t.Fatal("graph cannot be focused")
}
m = runKey(m, "home")
m = runKey(m, "l")
if m.runGraphTop != 0 || m.runGraphPan == 0 {
t.Fatal("graph scrolling/panning failed")
}
m = runKey(m, "g")
if m.runGraphFocus {
t.Fatal("cannot return to details")
}
for _, size := range [][2]int{{120, 36}, {70, 24}, {35, 18}, {10, 10}} {
m.width = size[0]
view := m.runsView(size[1])
if len(strings.Split(view, "\n")) > size[1] {
t.Fatal("run layout exceeds height", size)
}
for _, line := range strings.Split(view, "\n") {
if ansi.StringWidth(line) > size[0] {
t.Fatal("run layout exceeds width", size, ansi.StringWidth(line))
}
}
}
}
func TestRetryHiddenUntilExecutionAndAgentCleanupHaveCompleted(t *testing.T) {
m := New(context.Background(), "")
m.width = 180
m.runOpen = true
m.keys.runs = true
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Status: "failed", FinishedAt: "2026-10-09T00:00:00Z", Executing: true}}
if m.selectedFailedRun() != 0 || strings.Contains(m.runActions(), "retry") || strings.Contains(ansi.Strip(m.footerContent()), "retry") {
t.Fatal("retry advertised while execution is active")
}
m.runDetail.Executing = false
m.runDetail.Steps = []protocol.RunStep{{AgentActive: true}}
if m.selectedFailedRun() != 0 {
t.Fatal("retry available before agent cleanup")
}
m.runDetail.Steps[0].AgentActive = false
if m.selectedFailedRun() != 1 || !strings.Contains(m.runActions(), "retry") {
t.Fatal("fully stopped failed run lacks retry")
}
m.runDetail.FinishedAt = ""
if m.selectedFailedRun() != 0 {
t.Fatal("retry available before terminal timestamp")
}
}
func TestRunningDurationAndOpenCodeEvidenceShortcut(t *testing.T) {
duration, err := time.ParseDuration(runDuration(time.Now().Add(-65*time.Second).Format(time.RFC3339), ""))
if err != nil || duration < 65*time.Second || duration > 67*time.Second {
t.Fatal("elapsed running duration not shown", duration, err)
}
if got := runDuration("2026-10-09T00:00:00Z", "2026-10-09T00:01:02Z"); got != "1m2s" {
t.Fatal("finished duration changed", got)
}
m := runInspectionModel()
m.runDetail.Steps[1].AgentActive = true
m = runKey(m, "a")
if m.runStepIndex != 2 || !m.runDetailFocus || m.runSectionClosed(3) || !m.runSectionClosed(0) {
t.Fatal("OpenCode evidence shortcut did not select active session")
}
view := ansi.Strip(strings.Join(m.runSectionLines(90), "\n"))
if !strings.Contains(view, "ses_second") {
t.Fatal("session not exposed", view)
}
}
+43
View File
@@ -163,12 +163,55 @@ func (m Model) runFormView(height int) string {
func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
runs := m.visibleRuns()
if msg.String() == "g" && m.runDetail != nil {
m.runGraphFocus = !m.runGraphFocus
if m.runGraphFocus {
m.runGraphTop, m.runGraphPan = m.runGraphFollow()
}
return m, nil
}
if m.runGraphFocus {
switch msg.String() {
case "j", "down":
m.runGraphTop++
return m, nil
case "k", "up":
m.runGraphTop = max(0, m.runGraphTop-1)
return m, nil
case "h", "left":
m.runGraphPan = max(0, m.runGraphPan-8)
return m, nil
case "l", "right":
m.runGraphPan += 8
return m, nil
case "pgdown", "ctrl+d":
m.runGraphTop += max(1, m.height/2-4)
return m, nil
case "pgup", "ctrl+u":
m.runGraphTop = max(0, m.runGraphTop-max(1, m.height/2-4))
return m, nil
case "home":
m.runGraphTop = 0
return m, nil
case "end":
m.runGraphTop = len(m.runGraphLines(max(3, m.width-4)))
return m, nil
case "tab", "shift+tab":
m.runGraphFocus = false
return m, nil
}
}
switch msg.String() {
case "p":
return m.openRunPipeline()
case "D":
return m.debugRun()
case "a":
return m.openOpenCodeEvidence()
case "r":
return m.retrySelectedRun()
case "esc":
m.runGraphFocus = false
if m.runDetail != nil || m.requestedRunID > 0 || m.runStartRequest != "" {
m.runDetail = nil
m.requestedRunID = 0
+1 -1
View File
@@ -73,7 +73,7 @@ func TestRunSidebarSectionsAndScrolling(t *testing.T) {
if m.runStepIndex != 1 {
t.Fatal("sidebar did not select first attempt")
}
text := ansi.Strip(m.runsView(24))
text := ansi.Strip(m.runsDetailsView(24))
for _, want := range []string{"Stages", "▸ 1.", "2.", "done", "running", "Details · implementer · step 1", "Summary", "Output", "First attempt"} {
if !strings.Contains(text, want) {
t.Fatal("missing section/sidebar", want)