From d73a021cd47a3e84d2fcdff3c6229b920466c0f0 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 10 Oct 2026 02:00:39 +0100 Subject: [PATCH] Compact graph columns and branch spacing and simplify Home hints --- README.md | 5 +++ docs/cli.md | 5 +++ internal/tui/dashboard.go | 13 ++++---- internal/tui/dashboard_test.go | 46 ++++++++++++++++++++++++--- internal/tui/graph_compact_test.go | 41 ++++++++++++++++++++++++ internal/tui/graph_forks.go | 36 ++++++++++++++------- internal/tui/graph_layout.go | 22 +++++++------ internal/tui/home_failed_runs_test.go | 6 ++-- internal/tui/model.go | 5 ++- internal/tui/model_test.go | 2 +- internal/tui/stats.go | 2 +- 11 files changed, 146 insertions(+), 37 deletions(-) create mode 100644 internal/tui/graph_compact_test.go diff --git a/README.md b/README.md index 589a3dca..f70935b1 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,9 @@ pipelines retry requires confirmation and restarts the pinned workflow, so earlier side effects may happen again. +Home shows only **/** search and **:** commands as action hints; use the command +palette for creation, drafts, templates, history, status, logs, and quitting. + Quit with **:quit**; **q** does not exit. For a terminal-only run after publication: ```sh @@ -221,6 +224,8 @@ Use **:status** for two panels: server addresses and ntfy phone connection detai CLI: `pipelines status [--json]`. Candidate URLs are not verified reachable; publishing endpoints and credentials are not disclosed. Retry is offered only after the failed run and its agent have fully stopped. +Graphs use content-sized boxes/columns and tightly spaced branch lanes while +retaining every stage and labeled box-and-arrow route. The run inspector shows the entire pinned graph above the details, dimming stages and routes not executed. **g** focuses the graph; **hjkl** or arrows pan it. The path and elapsed duration update while running. **a** opens the active/latest diff --git a/docs/cli.md b/docs/cli.md index e10b104a..4eb893f3 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -210,6 +210,11 @@ pinned pipeline (lowercase `p` remains an alias only on the runs list). The pipeline page also gives most height to its focused graph or stage-details pane; Tab switches focus and resizes the two panes. Focused titles use the same background highlight as the run page. +Graph boxes are sized to their contents rather than the longest label anywhere +in the graph. Fork columns share only their own required width, route tracks are +adjacent, and branch spacing follows stacked boxes rather than tall trunk/merge +nodes. All stages, outcome labels, ports, and terminal arrows remain visible in +the full pannable diagram. 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 diff --git a/internal/tui/dashboard.go b/internal/tui/dashboard.go index a355b28b..5ec81fcf 100644 --- a/internal/tui/dashboard.go +++ b/internal/tui/dashboard.go @@ -27,6 +27,9 @@ func (m Model) footerContent() string { } else if len(m.lines) > 0 { style = lipgloss.NewStyle().Foreground(themeAccent).Bold(true) } + if m.homePage() { + label = strings.ReplaceAll(label, " · :logs", "") + } label = style.Render(ansi.Truncate(label, m.width, "")) available := m.width - lipgloss.Width(label) - 1 left := "" @@ -44,9 +47,7 @@ func (m Model) homeLines() []string { panelWidth = (m.width - 2) / 2 } runs := []string{bar("Latest runs", fmt.Sprint(len(m.runs)), max(1, panelWidth-4), true), - "r all runs · :status server & ntfy", - lipgloss.NewStyle().Foreground(themeMuted).Render("Pipeline · Version · Outcome · Duration"), - "Inspect with :runs; use :run in a pipeline."} + lipgloss.NewStyle().Foreground(themeMuted).Render("Pipeline · Version · Outcome · Duration")} if len(m.runs) == 0 { runs = append(runs, "No runs yet.") } @@ -58,13 +59,13 @@ func (m Model) homeLines() []string { runs = append(runs, "") } if len(m.runs) > 8 { - runs = append(runs, "More runs: r or :runs (latest 50)") + runs = append(runs, fmt.Sprintf("%d more runs in history", len(m.runs)-8)) } - lines := []string{bar("Existing pipelines", fmt.Sprintf("%d", len(m.pipelines)), max(1, panelWidth-4), true), "r all runs · / search · n new", ""} + lines := []string{bar("Existing pipelines", fmt.Sprintf("%d", len(m.pipelines)), max(1, panelWidth-4), true), ""} if !m.loaded { lines = append(lines, m.loading("Waiting for pipeline data…")) } else if len(m.pipelines) == 0 { - lines = append(lines, "No pipelines yet. Press b for templates, d for drafts, or n to create one.") + lines = append(lines, "No pipelines yet. Create one using commands.") } else { for _, p := range m.pipelines { lines = append(lines, diff --git a/internal/tui/dashboard_test.go b/internal/tui/dashboard_test.go index 194cbdc2..367570d5 100644 --- a/internal/tui/dashboard_test.go +++ b/internal/tui/dashboard_test.go @@ -28,8 +28,8 @@ func press(m Model, key string) Model { func TestPaletteAndUnreadLogs(t *testing.T) { m := New(context.Background(), "ws://localhost/connect") m.height = 18 - if !strings.Contains(ansi.Strip(m.footerContent()), "LOGS 0 · :logs") { - t.Fatal("expected empty log count and command hint") + if !strings.Contains(ansi.Strip(m.footerContent()), "LOGS 0") { + t.Fatal("expected empty log count") } for i := 0; i < 35; i++ { m.appendLine(fmt.Sprintf("line %02d", i)) @@ -95,14 +95,14 @@ func TestPaletteAndUnreadLogs(t *testing.T) { func TestLogBadgeRetainsReadLogs(t *testing.T) { m := New(context.Background(), "ws://localhost/connect") m.appendLine("connection lost") - if !strings.Contains(ansi.Strip(m.footerContent()), "● 1 NEW · LOGS 1 · :logs") { + if !strings.Contains(ansi.Strip(m.footerContent()), "● 1 NEW · LOGS 1") { t.Fatal("unread logs need an explicit badge") } m = press(m, ":") m = press(m, "logs") m = press(m, "enter") m = press(m, "esc") - if m.unread != 0 || !strings.Contains(ansi.Strip(m.footerContent()), "LOGS 1 · :logs") || strings.Contains(ansi.Strip(m.footerContent()), "NEW") { + if m.unread != 0 || !strings.Contains(ansi.Strip(m.footerContent()), "LOGS 1") || strings.Contains(ansi.Strip(m.footerContent()), "NEW") { t.Fatal("read logs must remain discoverable") } for _, width := range []int{1, 12, 40, 80} { @@ -120,7 +120,7 @@ func TestHomeShowsEmptyLatestRunsBeforePipelines(t *testing.T) { m.loaded = true m.pipelines = []protocol.PipelineSummary{{Name: "bug fix", Version: 3, Stages: 5}} view := ansi.Strip(m.View()) - for _, text := range []string{"Latest runs", "Outcome", "No runs yet.", "Inspect with :runs", "Existing pipelines", "bug fix"} { + for _, text := range []string{"Latest runs", "Outcome", "No runs yet.", "Existing pipelines", "bug fix"} { if !strings.Contains(view, text) { t.Fatalf("missing %q", text) } @@ -133,6 +133,42 @@ func TestHomeShowsEmptyLatestRunsBeforePipelines(t *testing.T) { } } +func TestHomeOnlyAdvertisesSearchAndCommands(t *testing.T) { + for _, populated := range []bool{false, true} { + m := New(context.Background(), "ws://localhost/connect") + m.width, m.height = 120, 40 + m.loaded = true + if populated { + m.pipelines = []protocol.PipelineSummary{{Name: "demo", Version: 1, Stages: 3}} + m.usage = &protocol.UsageStats{} + } + view := ansi.Strip(m.View()) + for _, hint := range []string{"/ search", ": commands"} { + if !strings.Contains(view, hint) { + t.Fatal("missing home hint", hint, view) + } + } + for _, hint := range []string{"r all runs", "n new", "d drafts", "b templates", "test ping", ":quit", ":status", ":logs", "Press b"} { + if strings.Contains(view, hint) { + t.Fatal("home advertises extra shortcut", hint, view) + } + } + if len(m.keys.ShortHelp()) != 2 { + t.Fatal("home help contains extra shortcuts") + } + available := m.pageCommands() + for _, command := range []string{":new", ":drafts", ":templates", ":runs", ":status", ":logs", ":quit"} { + if !strings.Contains(strings.Join(available, " "), command) { + t.Fatal("home action missing from commands", command) + } + } + m = press(m, ":") + if !m.paletteOpen { + t.Fatal("command palette inaccessible") + } + } +} + func TestDashboardAndModalDimensions(t *testing.T) { for _, size := range []tea.WindowSizeMsg{{Width: 100, Height: 30}, {Width: 40, Height: 10}, {Width: 12, Height: 5}, {Width: 1, Height: 1}} { for _, mode := range []string{"home", "palette", "logs"} { diff --git a/internal/tui/graph_compact_test.go b/internal/tui/graph_compact_test.go new file mode 100644 index 00000000..824fb5d6 --- /dev/null +++ b/internal/tui/graph_compact_test.go @@ -0,0 +1,41 @@ +package tui + +import ( + "fmt" + "strings" + "testing" + + "git.a-wan.net/alan/pipelines/internal/pipeline" + "git.a-wan.net/alan/pipelines/internal/protocol" + "github.com/charmbracelet/x/ansi" +) + +func TestCompactGraphDimensions(t *testing.T) { + linear, err := pipeline.Parse(pipeline.Template([]string{"plan", "implement_with_a_long_stage_name", "review", "publish"}, true)) + if err != nil { + t.Fatal(err) + } + for name, graph := range map[string]protocol.Graph{"linear": linear, "nested": nestedForkGraph(t)} { + layout := layoutGraph(graph) + t.Logf("%s: %d columns × %d rows", name, layout.width, layout.height) + // Measured before compaction: linear 175×15; nested forks 147×48. + if name == "linear" && (layout.width > 100 || layout.height > 15) { + t.Fatal("linear graph grew", layout.width, layout.height) + } + if name == "nested" && (layout.width > 118 || layout.height > 41) { + t.Fatal("fork graph grew", layout.width, layout.height) + } + assertForkRouteClearance(t, layout) + view := ansi.Strip(strings.Join(renderGraph(graph), "\n")) + for _, stage := range graph.Stages { + if !strings.Contains(view, stage.Key) { + t.Fatal("compaction lost stage", stage.Key) + } + } + for _, edge := range layout.edges { + if !strings.Contains(view, fmt.Sprintf("%s [%d]", edge.label, edge.id)) { + t.Fatal("compaction lost outcome", edge) + } + } + } +} diff --git a/internal/tui/graph_forks.go b/internal/tui/graph_forks.go index a0c2fd45..a01f513d 100644 --- a/internal/tui/graph_forks.go +++ b/internal/tui/graph_forks.go @@ -146,29 +146,43 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin } } gaps, xs := make([]int, maxColumn+2), make([]int, maxColumn+1) + widths := make([]int, maxColumn+1) + for i := 0; i < len(graph.Stages); i++ { + node := r.nodes[i] + widths[columns[node.key]] = max(widths[columns[node.key]], node.width) + } x := 0 for column := 0; column <= maxColumn; column++ { gaps[column] = x - x += 2*(outCount[column]+inCount[column]) + 3 + x += outCount[column] + inCount[column] + 3 xs[column] = x - x += r.nodeWidth + x += widths[column] } gaps[maxColumn+1] = x - x += 2*outCount[maxColumn+1] + 3 + x += outCount[maxColumn+1] + 3 r.width = x maxHeight := 0 + columnCounts := make([]int, maxColumn+1) + for _, stage := range graph.Stages { + columnCounts[columns[stage.Key]]++ + } for i := 0; i < len(graph.Stages); i++ { node := &r.nodes[i] node.height = incoming[node.key] + outgoing[node.key] + 4 if incoming[node.key] > 0 { node.height++ } - maxHeight = max(maxHeight, node.height) + // Only stacked branches set lane spacing; a tall trunk/merge must not + // inflate the spacing between every leaf in the graph. + if columnCounts[columns[node.key]] > 1 { + maxHeight = max(maxHeight, node.height) + } } - stride := maxHeight + 4 + stride := maxHeight + 2 for i := 0; i < len(graph.Stages); i++ { node := &r.nodes[i] node.x = xs[columns[node.key]] + node.width = widths[columns[node.key]] node.y = arcs + ticks[node.key]*stride/2 } // Irregular cross-branch merges can otherwise share a lane with an unrelated @@ -182,10 +196,10 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin } } sort.SliceStable(ids, func(i, j int) bool { return r.nodes[ids[i]].y < r.nodes[ids[j]].y }) - lastBottom := -4 + lastBottom := -2 for _, id := range ids { node := &r.nodes[id] - node.y = max(node.y, lastBottom+4) + node.y = max(node.y, lastBottom+2) lastBottom = node.y + node.height bottom = max(bottom, lastBottom) } @@ -241,7 +255,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin edge := &r.edges[i] source := nodes[edge.source] gap := columns[edge.source] + 1 - edge.x = gaps[gap] + 1 + 2*usedOut[gap] + edge.x = gaps[gap] + 1 + usedOut[gap] usedOut[gap]++ if protocol.IsTerminal(edge.target) { continue @@ -253,7 +267,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin edge.path = append(edge.path, graphPoint{edge.x, edge.to}, graphPoint{target.x, edge.to}) } else { gap := columns[edge.target] - track := gaps[gap] + 1 + 2*(outCount[gap]+usedIn[gap]) + track := gaps[gap] + 1 + outCount[gap] + usedIn[gap] usedIn[gap]++ edge.path = append(edge.path, graphPoint{edge.x, arc}, graphPoint{track, arc}, graphPoint{track, edge.to}, graphPoint{target.x, edge.to}) edge.lane = arc @@ -318,7 +332,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin } lanes[lane] = append(lanes[lane], interval) edge.lane = lane - row := bottom + 2 + lane + row := bottom + 1 + lane source := nodes[edge.source] edge.path = []graphPoint{{source.x + source.width - 1, edge.from}, {edge.x, edge.from}, {edge.x, row}, {destination, row}} if edge.bottomExit { @@ -327,7 +341,7 @@ func layoutForkGraph(graph protocol.Graph, columns map[string]int, order []strin edge.path = []graphPoint{{center, exit}, {center, exit + 1}, {edge.x, exit + 1}, {edge.x, row}, {destination, row}} } } - endY := bottom + len(lanes) + 3 + endY := bottom + len(lanes) + 2 for i := len(graph.Stages); i < len(r.nodes); i++ { node := terminal[r.nodes[i].key] node.y = endY diff --git a/internal/tui/graph_layout.go b/internal/tui/graph_layout.go index 6c4c0019..a6ddad8b 100644 --- a/internal/tui/graph_layout.go +++ b/internal/tui/graph_layout.go @@ -18,12 +18,13 @@ func layoutGraph(graph protocol.Graph) graphLayout { } func layoutSingleRowGraph(graph protocol.Graph) graphLayout { - r := graphLayout{edges: graphEdges(graph), nodeWidth: 16, positions: map[string]int{}} + r := graphLayout{edges: graphEdges(graph), positions: map[string]int{}} count := len(graph.Stages) index, incoming, outgoing := map[string]int{}, map[string][]int{}, map[string][]int{} + widths := map[string]int{} for i, s := range graph.Stages { index[s.Key] = i - r.nodeWidth = max(r.nodeWidth, len(s.Key)+6) + widths[s.Key] = max(14, len(s.Key)+4) } gapCount := make([]int, count+1) arcs := 0 @@ -34,7 +35,10 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout { if !r.edges[i].bottomExit { gapCount[index[e.source]+1]++ } - r.nodeWidth = max(r.nodeWidth, len(fmt.Sprintf("%s [%d]", e.label, e.id))+4) + widths[e.source] = max(widths[e.source], len(fmt.Sprintf("%s [%d]", e.label, e.id))+4) + if !protocol.IsTerminal(e.target) { + widths[e.target] = max(widths[e.target], len(fmt.Sprintf("in [%d]", e.id))+4) + } if !protocol.IsTerminal(e.target) && index[e.target] != index[e.source]+1 { arcs++ gapCount[index[e.target]]++ @@ -44,18 +48,18 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout { x, mainY, height := 0, arcs, 4 for i, s := range graph.Stages { gapStarts[i] = x - x += gapCount[i]*2 + 3 + x += gapCount[i] + 3 h := len(incoming[s.Key]) + len(outgoing[s.Key]) + 4 if len(incoming[s.Key]) > 0 { h++ } height = max(height, h) - r.nodes = append(r.nodes, graphNode{key: s.Key, x: x, y: mainY, width: r.nodeWidth, height: h}) + r.nodes = append(r.nodes, graphNode{key: s.Key, x: x, y: mainY, width: widths[s.Key], height: h}) r.positions[s.Key] = mainY - x += r.nodeWidth + x += widths[s.Key] } gapStarts[count] = x - x += gapCount[count]*2 + 3 + x += gapCount[count] + 3 r.width = x for i := range r.nodes { r.nodes[i].height = height @@ -112,7 +116,7 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout { } } usedOut, usedIn := make([]int, count+1), make([]int, count+1) - sourceTrack := func(gap int) int { value := gapStarts[gap] + 1 + usedOut[gap]*2; usedOut[gap]++; return value } + sourceTrack := func(gap int) int { value := gapStarts[gap] + 1 + usedOut[gap]; usedOut[gap]++; return value } targetTrack := func(gap int) int { outCount := 0 if gap > 0 { @@ -122,7 +126,7 @@ func layoutSingleRowGraph(graph protocol.Graph) graphLayout { } } } - value := gapStarts[gap] + 1 + (outCount+usedIn[gap])*2 + value := gapStarts[gap] + 1 + outCount + usedIn[gap] usedIn[gap]++ return value } diff --git a/internal/tui/home_failed_runs_test.go b/internal/tui/home_failed_runs_test.go index 6a303eba..353e9f99 100644 --- a/internal/tui/home_failed_runs_test.go +++ b/internal/tui/home_failed_runs_test.go @@ -13,7 +13,7 @@ import ( "github.com/charmbracelet/x/ansi" ) -func TestHomeShortcutOpensAllRunsAndDisplaysHintInBothPanels(t *testing.T) { +func TestHomeShortcutOpensAllRunsWithoutClutteringPanels(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() srv := httptest.NewServer(server.Handler(ctx)) @@ -27,8 +27,8 @@ func TestHomeShortcutOpensAllRunsAndDisplaysHintInBothPanels(t *testing.T) { m.height = 40 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 all runs") < 2 || strings.Contains(view, "r failed runs") { - t.Fatal("missing shortcut in both panels", view) + if strings.Contains(view, "r all runs") || strings.Contains(view, "r failed runs") { + t.Fatal("shortcut hints clutter home panels", view) } updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}}) m = updated.(Model) diff --git a/internal/tui/model.go b/internal/tui/model.go index 754038b6..c0e83b15 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -85,7 +85,7 @@ func (k keyMap) ShortHelp() []key.Binding { 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"))} } - return []key.Binding{k.commands, k.search, k.create, key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "all runs")), key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "drafts")), key.NewBinding(key.WithKeys("b"), key.WithHelp("b", "templates")), k.ping, k.quit} + return []key.Binding{k.search, k.commands} } func (k keyMap) FullHelp() [][]key.Binding { return [][]key.Binding{k.ShortHelp()} } @@ -650,6 +650,9 @@ func (m Model) View() string { connection := m.status if m.conn != nil { connection = "Connected · :status" + if m.homePage() { + connection = "Connected" + } } if m.conn == nil { connection = m.loading(connection) diff --git a/internal/tui/model_test.go b/internal/tui/model_test.go index 5f4f8312..08772c17 100644 --- a/internal/tui/model_test.go +++ b/internal/tui/model_test.go @@ -87,7 +87,7 @@ func TestLayoutResizes(t *testing.T) { if !strings.HasPrefix(lines[0], "Pipelines ") || !strings.HasSuffix(lines[0], "127.0.0.1:8080") || lipgloss.Width(lines[0]) != size.Width { t.Fatalf("invalid header: %q", lines[0]) } - if !strings.HasPrefix(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") || !strings.HasSuffix(lines[len(lines)-1], ":logs ") { + if !strings.HasPrefix(lines[len(lines)-1], "/ search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") { t.Fatalf("invalid footer: %q", lines[len(lines)-1]) } if strings.TrimSpace(lines[len(lines)-2]) != "" { diff --git a/internal/tui/stats.go b/internal/tui/stats.go index 731569c3..f5e1462a 100644 --- a/internal/tui/stats.go +++ b/internal/tui/stats.go @@ -40,7 +40,7 @@ func usageChart(days []protocol.DailyUsage) string { func (m Model) usageLines() []string { lines := []string{"Usage · all history"} if m.usage == nil { - return append(lines, m.loading("Waiting for usage statistics…"), ":status server & ntfy · r all runs") + return append(lines, m.loading("Waiting for usage statistics…")) } c := m.usage.RunCounts lines = append(lines, fmt.Sprintf("%d pipelines · %d runs · %d active · %s · avg completed %s", len(m.pipelines), c.Total, c.Active, successLabel(c), averageLabel(c)), fmt.Sprintf("Outcomes: %d succeeded · %d failed · %d canceled · %d interrupted", c.Succeeded, c.Failed, c.Canceled, c.Interrupted))