diff --git a/docs/cli.md b/docs/cli.md index 5d69e5d6..53a1ddcc 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -155,7 +155,7 @@ transient client logs are presentation, not separate server capabilities. ## Scripted runs -On either the runs list or run inspector, press `p` (or use `:pipeline`) to open +On either the runs list or run inspector, press `P` (or use `:pipeline`) to open the selected run's exact pipeline version. Navigation does not cancel the run. Initial input includes `pwd`, the resolved run directory (normally the directory @@ -188,6 +188,14 @@ or Tab to return to details. When not focused, the graph follows the latest visi or selected stage. Existing polling refreshes the graph once per second, and running durations show elapsed time rather than “in progress.” +In the run inspector, `n`/`p` select the next/previous recorded execution visit, +including repeated visits in loops, from any pane. Selection stops at the last +visit or overview; it does not wrap. The selected stage has a full-row highlight; +the focused stage/details pane has a highlighted title and pointer. In details, +the section containing the top visible row is highlighted and named in the pane +title. `Tab` switches stage/details focus; `g` switches graph focus. `P` opens the +pinned pipeline (lowercase `p` remains an alias only on the runs list). + Press `a` to select the active/latest retained OpenCode agent session and open its tool evidence. Session ID is available during execution; tool transcripts appear when persisted (currently after generation). This does not attach a live OpenCode diff --git a/internal/tui/model.go b/internal/tui/model.go index b311c639..58b3e6be 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -76,7 +76,7 @@ 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 { - 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"))} + bindings := []key.Binding{k.commands, key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "next/prev stage")), 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"))) } diff --git a/internal/tui/run_detail.go b/internal/tui/run_detail.go index b8a3a4f7..0064507a 100644 --- a/internal/tui/run_detail.go +++ b/internal/tui/run_detail.go @@ -441,9 +441,46 @@ func (m Model) runSectionLines(width int) []string { } lines = append(lines, "") } + if m.runDetailFocus && !m.runGraphFocus { + row, _ := runFocusedSection(lines, m.runTop) + lines[row] = runHighlight(lines[row], width) + } return lines } +// The section containing the top visible detail row is the scroll focus. +func runFocusedSection(lines []string, top int) (int, string) { + row, title := 0, "Summary" + for i, line := range lines { + plain := ansi.Strip(line) + if i > top { + break + } + if len(plain) > 4 && plain[0] == '[' && plain[2] == ']' { + row = i + fields := strings.Fields(plain) + if len(fields) > 2 { + title = strings.Join(fields[2:], " ") + } + } + } + return row, title +} + +func runHighlight(text string, width int) string { + text = ansi.Truncate(text, max(1, width), "…") + text += strings.Repeat(" ", max(0, width-ansi.StringWidth(text))) + return lipgloss.NewStyle().Foreground(themeAccent).Background(themeSelection).Bold(true). + Render(surfaceContent(text, themeSelection)) +} + +func runPaneTitle(title, right string, width int, focused bool) string { + if focused { + return runHighlight(bar("▸ "+title, right, width, true), width) + } + return bar(title, right, width, false) +} + func (m Model) runSelectionLabel() string { if m.runDetail != nil && m.runStepIndex > 0 && m.runStepIndex <= len(m.runDetail.Steps) { step := m.runDetail.Steps[m.runStepIndex-1] @@ -453,7 +490,10 @@ func (m Model) runSelectionLabel() string { } func (m Model) runActions() string { - text := "p pipeline" + text := "P pipeline" + if m.runDetail != nil { + text = "n/p next/prev stage · " + text + } if m.selectedRunID() > 0 { text += " · D debug" } @@ -512,7 +552,7 @@ func (m Model) runsDetailsView(height int) string { 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(), m.runActions() + " · Tab pane · Esc back"}, m.width, height) + return fitBlock([]string{header, runHighlight(m.runSelectionLabel(), m.width), m.runActions() + " · Tab pane · Esc back"}, m.width, height) } innerHeight := height - 2 sidebar := m.runSidebarWidth() @@ -536,18 +576,16 @@ func (m Model) runsDetailsView(height int) string { } text := ansi.Truncate(prefix+labels[i], sidebar-4, "…") if i == m.runStepIndex { - text = bar(text, "", sidebar-4, true) + text = runHighlight(text, sidebar-4) } body = append(body, text) } label := "Stages" - if !m.runDetailFocus { - label = "▸ " + label - } - left = panel(sidebar, innerHeight, []string{bar(label, fmt.Sprint(len(r.Steps)), sidebar-4, !m.runDetailFocus)}, body, "1–9 stage · 0 overview", !m.runDetailFocus) + focused := !m.runDetailFocus && !m.runGraphFocus + left = panel(sidebar, innerHeight, []string{runPaneTitle(label, fmt.Sprint(len(r.Steps)), sidebar-4, focused)}, body, "n/p stage · 0 overview", focused) } else { innerHeight-- - header += "\n" + ansi.Truncate(m.runSelectionLabel()+" · h/l pane · j/k select/scroll", m.width, "…") + header += "\n" + runHighlight(m.runSelectionLabel()+" · n/p stage · Tab pane", m.width) } lines := m.runSectionLines(max(1, rightWidth-4)) page := max(0, innerHeight-4) @@ -557,10 +595,12 @@ func (m Model) runsDetailsView(height int) string { 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) } - if m.runDetailFocus { - label = "▸ " + label + focused := m.runDetailFocus && !m.runGraphFocus + if focused { + _, section := runFocusedSection(lines, top) + label += " · " + section } - right := panel(rightWidth, innerHeight, []string{bar(label, "", max(1, rightWidth-4), m.runDetailFocus)}, lines[top:min(len(lines), top+page)], footer, m.runDetailFocus) + right := panel(rightWidth, innerHeight, []string{runPaneTitle(label, "", max(1, rightWidth-4), focused)}, lines[top:min(len(lines), top+page)], footer, focused) body := right if sidebar > 0 { body = lipgloss.JoinHorizontal(lipgloss.Top, left, " ", right) diff --git a/internal/tui/run_focus_test.go b/internal/tui/run_focus_test.go new file mode 100644 index 00000000..aebde6dd --- /dev/null +++ b/internal/tui/run_focus_test.go @@ -0,0 +1,93 @@ +package tui + +import ( + "strings" + "testing" + + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" + "github.com/muesli/termenv" +) + +func TestRunNextPreviousNavigatesExecutionVisitsFromEveryPane(t *testing.T) { + for _, pane := range []string{"stages", "details", "graph"} { + t.Run(pane, func(t *testing.T) { + m := runInspectionModel() + m.width = 100 + m.runDetail.Steps[1].Stage = m.runDetail.Steps[0].Stage + m.runDetailFocus = pane == "details" + m.runGraphFocus = pane == "graph" + m.runTop = 7 + m = runKey(m, "n") + if m.runStepIndex != 1 || m.runTop != 0 || !m.runOpen { + t.Fatal("next stage did not select first recorded visit") + } + m = runKey(m, "n") + if m.runStepIndex != 2 { + t.Fatal("repeated stage visit skipped") + } + m = runKey(m, "n") + if m.runStepIndex != 2 { + t.Fatal("next stage wrapped past last visit") + } + m = runKey(m, "p") + if m.runStepIndex != 1 || !m.runOpen { + t.Fatal("previous stage opened pipeline") + } + m = runKey(m, "p") + m = runKey(m, "p") + if m.runStepIndex != 0 || !m.runOpen { + t.Fatal("previous stage wrapped before overview") + } + if m.runDetailFocus != (pane == "details") || m.runGraphFocus != (pane == "graph") { + t.Fatal("navigation unexpectedly changed focus") + } + }) + } +} + +func TestRunFocusHighlightsSelectionPaneAndVisibleSection(t *testing.T) { + previous := lipgloss.ColorProfile() + lipgloss.SetColorProfile(termenv.TrueColor) + defer lipgloss.SetColorProfile(previous) + m := runInspectionModel() + m.width = 120 + m = runKey(m, "n") + view := m.runsDetailsView(30) + if !strings.Contains(ansi.Strip(view), "▸ Stages") || !strings.Contains(view, "48;") { + t.Fatal("stage pane/selection lacks background highlight") + } + m = runKey(m, "tab") + lines := m.runSectionLines(80) + row, title := runFocusedSection(lines, 0) + if title != "Summary" || !strings.Contains(lines[row], "48;") { + t.Fatal("focused section not highlighted", lines[row]) + } + for i, line := range lines { + if strings.HasPrefix(ansi.Strip(line), "[o]") { + m.runTop = i + break + } + } + lines = m.runSectionLines(80) + row, title = runFocusedSection(lines, m.runTop) + if title != "Output" || !strings.Contains(lines[row], "48;") { + t.Fatal("scroll focus did not follow section", title) + } + view = ansi.Strip(m.runsDetailsView(30)) + if !strings.Contains(view, "▸ Details") || !strings.Contains(view, "· Output") || strings.Contains(view, "▸ Stages") { + t.Fatal("focused pane ambiguous", view) + } + m = runKey(m, "g") + if !strings.HasPrefix(m.runGraphTitle(), "▸ ") || strings.Contains(ansi.Strip(m.runsDetailsView(30)), "▸ Details") { + t.Fatal("graph focus left details highlighted") + } + for _, width := range []int{120, 63, 35, 10} { + m.width = width + for _, line := range strings.Split(m.runsView(24), "\n") { + if ansi.StringWidth(line) > width { + t.Fatal("highlight exceeded viewport", width) + } + } + } +} diff --git a/internal/tui/run_graph.go b/internal/tui/run_graph.go index 5a0d9ae9..fc5ed886 100644 --- a/internal/tui/run_graph.go +++ b/internal/tui/run_graph.go @@ -105,6 +105,9 @@ func (m Model) runGraphTitle() string { durationLabel = "duration" } title := "Run graph · " + durationLabel + " " + runDuration(r.CreatedAt, r.FinishedAt) + " · started " + dateLabel(r.CreatedAt) + if m.runGraphFocus { + title = "▸ " + title + } if r.FinishedAt != "" { title += " · finished " + dateLabel(r.FinishedAt) } diff --git a/internal/tui/run_pipeline_test.go b/internal/tui/run_pipeline_test.go index 72180410..3b2316ba 100644 --- a/internal/tui/run_pipeline_test.go +++ b/internal/tui/run_pipeline_test.go @@ -61,7 +61,7 @@ func TestRunPageOpensPinnedPipelineWithoutCancellingRun(t *testing.T) { if !slices.Contains(m.pageCommands(), ":pipeline") { t.Fatal("run page is missing pipeline command") } - updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'p'}}) + updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'P'}}) m = updated.(Model) if send == nil || m.runOpen || !m.detailLoading || m.requestedPipelineID != id || m.requestedVersion != 1 || !m.cliStarted { t.Fatal("incorrect run-to-pipeline navigation") diff --git a/internal/tui/runs.go b/internal/tui/runs.go index ef888f99..c1a47b9b 100644 --- a/internal/tui/runs.go +++ b/internal/tui/runs.go @@ -225,6 +225,17 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) { m.runSearchOpen = true return m, m.runSearch.Focus() } + if m.runDetail != nil && (msg.String() == "n" || msg.String() == "p") { + delta := 1 + if msg.String() == "p" { + delta = -1 + } + m.selectRunStep(max(0, min(len(m.runDetail.Steps), m.runStepIndex+delta))) + if m.runGraphFocus { + m.runGraphTop, m.runGraphPan = m.runGraphFollow() + } + return m, nil + } runs := m.visibleRuns() if msg.String() == "g" && m.runDetail != nil { m.runGraphFocus = !m.runGraphFocus @@ -265,6 +276,8 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } } switch msg.String() { + case "P": + return m.openRunPipeline() case "p": return m.openRunPipeline() case "D":