Add live stage progress and centered auto-fitting run graphs

This commit is contained in:
2026-10-10 00:37:35 +01:00
parent dac34b0097
commit f8ffde92f7
5 changed files with 270 additions and 16 deletions
+7 -1
View File
@@ -193,7 +193,13 @@ 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
title. `Tab` cycles stages → details → graph (Shift+Tab reverses); `g` switches
graph focus. Each graph stage title shows live progress from its latest execution
visit, with pending stages dimmed. The graph is centered horizontally/vertically
when it fits; if the detailed diagram is too large, a compact branch overview
keeps all stage names, progress and declared routes. Oversized overviews remain
pannable with `h/j/k/l` or arrows while the graph is focused; `c` recenters the
selected/current stage. `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
+50 -3
View File
@@ -108,6 +108,53 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
type graphAppearance struct {
nodes map[string]bool
routes map[graphRoute]bool
labels map[string]string
}
func (a *graphAppearance) label(key string) string {
if a != nil && a.labels[key] != "" {
return a.labels[key]
}
return nodeLabel(key)
}
func layoutGraphAppearance(graph protocol.Graph, appearance *graphAppearance) graphLayout {
if appearance == nil || len(appearance.labels) == 0 {
return layoutGraph(graph)
}
display := protocol.Graph{}
keys := map[string]string{}
label := func(key string) string {
if protocol.IsTerminal(key) {
return key
}
return appearance.label(key)
}
for _, stage := range graph.Stages {
copy := stage
copy.Key = label(stage.Key)
keys[copy.Key] = stage.Key
copy.Edges = map[string]string{}
for outcome, target := range stage.Edges {
copy.Edges[outcome] = label(protocol.ResolveTarget(outcome, target))
}
display.Stages = append(display.Stages, copy)
}
layout := layoutGraph(display)
for i, node := range layout.nodes {
if key, ok := keys[node.key]; ok {
layout.nodes[i].key = key
}
}
for i, edge := range layout.edges {
if key, ok := keys[edge.source]; ok {
layout.edges[i].source = key
}
if key, ok := keys[edge.target]; ok {
layout.edges[i].target = key
}
}
return layout
}
type graphRoute struct{ source, outcome, target string }
@@ -145,7 +192,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
var lines []string
edges, index := graphEdges(graph), 0
for _, stage := range graph.Stages {
lines = append(lines, appearance.title(stage.Key, "["+stage.Key+"]", stage.Key == selected, graph))
lines = append(lines, appearance.title(stage.Key, "["+appearance.label(stage.Key)+"]", stage.Key == selected, graph))
for range outcomes(stage) {
e := edges[index]
index++
@@ -156,7 +203,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
}
return append(lines, appearance.title(protocol.FailureEnd, "[FAILURE]", false, graph)+" "+appearance.title(protocol.SuccessEnd, "[SUCCESS]", false, graph))
}
layout := layoutGraph(graph)
layout := layoutGraphAppearance(graph, appearance)
type cell struct {
glyph rune
color lipgloss.Color
@@ -303,7 +350,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
result[row] = b.String()
}
for _, node := range layout.nodes {
label, row := nodeLabel(node.key), node.y+1
label, row := appearance.label(node.key), node.y+1
left := ansi.Cut(result[row], 0, node.x+1)
title := " " + label + strings.Repeat(" ", node.width-3-ansi.StringWidth(label))
right := ansi.Cut(result[row], node.x+node.width-1, layout.width)
+80 -5
View File
@@ -5,6 +5,8 @@ import (
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)
// Each visit is a separate node, preserving cycles. Only recorded routes are drawn.
@@ -63,9 +65,13 @@ func (m Model) runGraphState() (protocol.Graph, string, *graphAppearance) {
}
return graph, selected, nil
}
appearance := &graphAppearance{nodes: map[string]bool{}, routes: map[graphRoute]bool{}}
appearance := &graphAppearance{nodes: map[string]bool{}, routes: map[graphRoute]bool{}, labels: map[string]string{}}
for _, stage := range graph.Stages {
appearance.labels[stage.Key] = stage.Key + " · ○ pending"
}
for _, step := range r.Steps {
appearance.nodes[step.Stage] = true
appearance.labels[step.Stage] = step.Stage + " · " + ansi.Strip(m.progress(m.stepProgressStatus(step)))
if step.Target != "" && step.Outcome != "" {
target := protocol.ResolveTarget(step.Outcome, step.Target)
appearance.routes[graphRoute{step.Stage, step.Outcome, target}] = true
@@ -90,7 +96,7 @@ func (m Model) runsView(height int) string {
if !m.runGraphFocus {
top, pan = m.runGraphFollow()
}
graph := graphViewport(m.runGraphTitle(), m.runGraphLines(max(3, m.width-4)), m.width, graphHeight, top, pan, m.runGraphFocus, "g graph/details · arrows pan · j/k scroll · dim = not executed")
graph := m.runGraphPanel(graphHeight, top, pan)
details := m.runsDetailsView(height - graphHeight)
return fitBlock(strings.Split(graph+"\n"+details, "\n"), m.width, height)
}
@@ -115,15 +121,84 @@ func (m Model) runGraphTitle() string {
}
func (m Model) runGraphFollow() (int, int) {
graph, selected, _ := m.runGraphState()
graph, selected, appearance := m.runGraphState()
if len(graph.Stages) == 0 {
return 0, 0
}
layout := layoutGraph(graph)
rows := max(1, (m.height-4)/2-5)
lines, compact := m.fittedRunGraph(max(1, m.width-4), rows)
if compact {
for i, line := range lines {
if strings.HasPrefix(ansi.Strip(line), "▸ ") {
return max(0, i-rows/2), 0
}
}
return 0, 0
}
layout := layoutGraphAppearance(graph, appearance)
for _, node := range layout.nodes {
if node.key == selected {
return node.y, max(0, node.x-(m.width-4-node.width)/2)
return max(0, node.y-rows/2), max(0, node.x-(m.width-4-node.width)/2)
}
}
return 0, 0
}
func (m Model) fittedRunGraph(width, rows int) ([]string, bool) {
lines := m.runGraphLines(width)
widest := 0
for _, line := range lines {
widest = max(widest, ansi.StringWidth(line))
}
if widest <= width && len(lines) <= rows {
return lines, false
}
graph, selected, appearance := m.runGraphState()
if appearance == nil {
return lines, false
}
// Dense overview preserves every declared branch, rather than hiding nodes
// or scaling terminal text into unreadable glyphs.
lines = nil
for _, stage := range graph.Stages {
prefix := " "
if stage.Key == selected {
prefix = "▸ "
}
line := prefix + appearance.title(stage.Key, appearance.label(stage.Key), stage.Key == selected, graph)
for _, outcome := range outcomes(stage) {
target := protocol.ResolveTarget(outcome, stage.Edges[outcome])
color, bold := appearance.edgeStyle(graphEdge{source: stage.Key, outcome: outcome, target: target})
line += " " + lipgloss.NewStyle().Foreground(color).Bold(bold).Render(outcome+" → "+nodeLabel(target))
}
lines = append(lines, strings.Split(ansi.Wrap(line, max(1, width), ""), "\n")...)
}
lines = append(lines, appearance.title(protocol.SuccessEnd, "SUCCESS", false, graph)+" "+appearance.title(protocol.FailureEnd, "FAILURE", false, graph))
return lines, true
}
func (m Model) runGraphPanel(height, top, pan int) string {
width, rows := max(1, m.width-4), max(0, height-5)
lines, compact := m.fittedRunGraph(width, rows)
widest := 0
for _, line := range lines {
widest = max(widest, ansi.StringWidth(line))
}
pan = max(0, min(pan, max(0, widest-width)))
top = max(0, min(top, max(0, len(lines)-rows)))
leftPad, topPad := max(0, (width-widest)/2), max(0, (rows-len(lines))/2)
body := make([]string, topPad)
for _, line := range lines[top:min(len(lines), top+rows-topPad)] {
body = append(body, strings.Repeat(" ", leftPad)+ansi.Cut(line, pan, pan+width-leftPad))
}
label := m.runGraphTitle()
if compact {
label += " · compact"
}
footer := "Tab pane · n/p stage · dim = not executed"
if widest > width || len(lines) > rows {
footer = "h/j/k/l pan · c center · Tab pane · n/p stage"
}
header := runPaneTitle(strings.TrimPrefix(label, "▸ "), "", width, m.runGraphFocus)
return panel(m.width, height, []string{header, ""}, body, footer, m.runGraphFocus)
}
+111
View File
@@ -0,0 +1,111 @@
package tui
import (
"context"
"fmt"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func TestRunGraphStageTitlesShowLatestVisitProgress(t *testing.T) {
m := New(context.Background(), "")
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{Status: "running"}, Graph: protocol.Graph{Stages: []protocol.Stage{
{Key: "plan", Edges: map[string]string{"success": "work"}},
{Key: "work", Edges: map[string]string{"revise": "plan", "success": "report"}},
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
}}, Steps: []protocol.RunStep{{Stage: "plan", Status: "completed"}, {Stage: "work", Status: "completed"}, {Stage: "plan", Status: "running"}}}
view := ansi.Strip(strings.Join(m.runGraphLines(120), "\n"))
for _, want := range []string{"plan ·", "running", "work · ✓ done", "report · ○ pending"} {
if !strings.Contains(view, want) {
t.Fatal("stage progress absent", want, view)
}
}
if strings.Contains(view, "plan · ✓ done") {
t.Fatal("earlier loop visit hid current progress")
}
m.runDetail.Steps[2].Status = "failed"
view = ansi.Strip(strings.Join(m.runGraphLines(120), "\n"))
if !strings.Contains(view, "plan · ✗ failed") || strings.Contains(view, "running") {
t.Fatal("progress did not refresh", view)
}
}
func TestRunGraphAutoFitsAndCentersCompactOverview(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 120, 40
m.runDetail = &protocol.RunDetail{Graph: protocol.Graph{Stages: []protocol.Stage{
{Key: "sum", Edges: map[string]string{"success": "multiply", "error": protocol.FailureEnd}},
{Key: "multiply", Edges: map[string]string{"success": "parity"}},
{Key: "parity", Edges: map[string]string{"odd": "add_one", "even": "halve"}},
{Key: "halve", Edges: map[string]string{"success": "report"}},
{Key: "add_one", Edges: map[string]string{"success": "report"}},
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
}}}
lines, compact := m.fittedRunGraph(116, 15)
if !compact || len(lines) > 15 {
t.Fatal("ordinary run graph did not fit", len(lines), compact)
}
for _, line := range lines {
if ansi.StringWidth(line) > 116 {
t.Fatal("compact graph exceeds available width")
}
}
view := ansi.Strip(m.runGraphPanel(20, 999, 999))
for _, want := range []string{"sum · ○ pending", "halve · ○ pending", "add_one · ○ pending", "odd → add_one", "even → halve", "SUCCESS", "FAILURE"} {
if !strings.Contains(view, want) {
t.Fatal("fitting hid stage or branch", want, view)
}
}
if strings.Contains(view, "h/j/k/l pan") {
t.Fatal("fitted overview still requests scrolling")
}
for _, line := range strings.Split(view, "\n") {
if strings.Contains(line, "sum ·") && strings.Index(line, "sum ·") < 10 {
t.Fatal("graph was not horizontally centered", line)
}
}
}
func TestRunTabCycleAndGraphPanning(t *testing.T) {
m := runInspectionModel()
m.width, m.height = 40, 24
for i := 0; i < 30; i++ {
m.runDetail.Graph.Stages = append(m.runDetail.Graph.Stages, protocol.Stage{Key: fmt.Sprintf("node_%02d", i), Edges: map[string]string{"success": protocol.SuccessEnd}})
}
m = runKey(m, "tab")
if !m.runDetailFocus || m.runGraphFocus {
t.Fatal("Tab did not focus details")
}
m = runKey(m, "tab")
if !m.runGraphFocus || m.runDetailFocus {
t.Fatal("Tab did not focus graph")
}
m = runKey(m, "j")
if m.runGraphTop == 0 {
t.Fatal("j did not pan graph vertically")
}
m = runKey(m, "l")
if m.runGraphPan == 0 {
t.Fatal("l did not pan graph horizontally")
}
m = runKey(m, "h")
m = runKey(m, "k")
if m.runGraphPan != 0 || m.runGraphTop != 0 {
t.Fatal("h/k did not pan back")
}
m = runKey(m, "tab")
if m.runGraphFocus || m.runDetailFocus {
t.Fatal("Tab did not return to stages")
}
m = runKey(m, "shift+tab")
if !m.runGraphFocus {
t.Fatal("reverse Tab cycle skipped graph")
}
view := ansi.Strip(m.runGraphPanel(10, 0, 0))
if !strings.Contains(view, "h/j/k/l") {
t.Fatal("oversized graph omitted pan hint", view)
}
}
+22 -7
View File
@@ -236,6 +236,25 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
return m, nil
}
if m.runDetail != nil && (msg.String() == "tab" || msg.String() == "shift+tab") {
pane := 0
if m.runDetailFocus {
pane = 1
}
if m.runGraphFocus {
pane = 2
}
if msg.String() == "tab" {
pane = (pane + 1) % 3
} else {
pane = (pane + 2) % 3
}
m.runDetailFocus, m.runGraphFocus = pane == 1, pane == 2
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
@@ -246,6 +265,9 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
if m.runGraphFocus {
switch msg.String() {
case "c":
m.runGraphTop, m.runGraphPan = m.runGraphFollow()
return m, nil
case "j", "down":
m.runGraphTop++
return m, nil
@@ -270,9 +292,6 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
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() {
@@ -321,10 +340,6 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.runDetail != nil {
m.runDetailFocus = true
}
case "tab", "shift+tab":
if m.runDetail != nil {
m.runDetailFocus = !m.runDetailFocus
}
case "h", "left":
m.runDetailFocus = false
case "l", "right":