Show full audited run graphs and scope searchable run history

This commit is contained in:
2026-10-10 00:26:32 +01:00
parent a1c0eb4a72
commit e9a8eaf8ae
15 changed files with 438 additions and 66 deletions
+55 -15
View File
@@ -96,25 +96,65 @@ func graphStageRow(graph protocol.Graph, key string) int {
}
func renderGraph(graph protocol.Graph, selection ...string) []string {
if len(graph.Stages) == 0 {
return []string{"(empty graph)"}
}
selected := ""
if len(selection) > 0 {
selected = selection[0]
}
return renderGraphAppearance(graph, selected, nil)
}
// A nil appearance is the normal definition view. Run views dim all nodes and
// routes not present in the audit, without removing any definition branches.
type graphAppearance struct {
nodes map[string]bool
routes map[graphRoute]bool
}
type graphRoute struct{ source, outcome, target string }
func (a *graphAppearance) nodeColor(key string, graph protocol.Graph) lipgloss.Color {
if a != nil && !a.nodes[key] {
return themeMuted
}
return stageColor(key, graph)
}
func (a *graphAppearance) title(key, label string, selected bool, graph protocol.Graph) string {
if a == nil {
return stageTitle(key, label, selected, graph)
}
s := lipgloss.NewStyle().Foreground(a.nodeColor(key, graph)).Bold(a.nodes[key])
if selected {
s = s.Background(themeSelection)
}
return s.Render(label)
}
func (a *graphAppearance) edgeStyle(edge graphEdge) (lipgloss.Color, bool) {
if a != nil && !a.routes[graphRoute{edge.source, edge.outcome, edge.target}] {
return themeMuted, false
}
return outcomeColor(edge.outcome), true
}
func renderGraphAppearance(graph protocol.Graph, selected string, appearance *graphAppearance) []string {
if len(graph.Stages) == 0 {
return []string{"(empty graph)"}
}
if compactGraph(graph) {
var lines []string
edges, index := graphEdges(graph), 0
for _, stage := range graph.Stages {
lines = append(lines, stageTitle(stage.Key, "["+stage.Key+"]", stage.Key == selected, graph))
lines = append(lines, appearance.title(stage.Key, "["+stage.Key+"]", stage.Key == selected, graph))
for range outcomes(stage) {
e := edges[index]
index++
lines = append(lines, " "+outcomeLabel(e.outcome, fmt.Sprintf("└─ %s [%d] → ", e.label, e.id))+stageTitle(e.target, "["+nodeLabel(e.target)+"]", false, graph))
color, bold := appearance.edgeStyle(e)
label := lipgloss.NewStyle().Foreground(color).Bold(bold).Render(fmt.Sprintf("└─ %s [%d] → ", e.label, e.id))
lines = append(lines, " "+label+appearance.title(e.target, "["+nodeLabel(e.target)+"]", false, graph))
}
}
return append(lines, stageTitle(protocol.FailureEnd, "[FAILURE]", false)+" "+stageTitle(protocol.SuccessEnd, "[SUCCESS]", false))
return append(lines, appearance.title(protocol.FailureEnd, "[FAILURE]", false, graph)+" "+appearance.title(protocol.SuccessEnd, "[SUCCESS]", false, graph))
}
layout := layoutGraph(graph)
type cell struct {
@@ -140,7 +180,7 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
for _, node := range layout.nodes {
nodes[node.key] = node
x, w, y, h := node.x, node.width, node.y, node.height
color := stageColor(node.key, graph)
color := appearance.nodeColor(node.key, graph)
active := node.key == selected
top, bottom, vertical := "╭"+strings.Repeat("─", w-2)+"╮", "╰"+strings.Repeat("─", w-2)+"╯", '│'
if active {
@@ -175,7 +215,7 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
}
}
for _, edge := range layout.edges {
color := outcomeColor(edge.outcome)
color, bold := appearance.edgeStyle(edge)
path := []graphPoint{}
for i := 1; i < len(edge.path); i++ {
a, b := edge.path[i-1], edge.path[i]
@@ -221,21 +261,21 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
}
start, end := path[0], path[len(path)-1]
if edge.bottomExit {
put(start.x, start.y, '▼', color, true)
put(start.x, start.y, '▼', color, bold)
} else {
put(start.x, start.y, '├', color, false)
put(start.x+1, start.y, '→', color, false)
}
if edge.topEntry {
put(end.x, end.y, '▼', color, true)
text(end.x-1, end.y-1, fmt.Sprintf("[%d]", edge.id), color, true)
put(end.x, end.y, '▼', color, bold)
text(end.x-1, end.y-1, fmt.Sprintf("[%d]", edge.id), color, bold)
} else {
put(end.x, end.y, '▶', color, true)
put(end.x, end.y, '▶', color, bold)
target := nodes[edge.target]
text(target.x+2, edge.to, fmt.Sprintf("in [%d]", edge.id), color, true)
text(target.x+2, edge.to, fmt.Sprintf("in [%d]", edge.id), color, bold)
}
source := nodes[edge.source]
text(source.x+2, edge.from, fmt.Sprintf("%s [%d]", edge.label, edge.id), color, true)
text(source.x+2, edge.from, fmt.Sprintf("%s [%d]", edge.label, edge.id), color, bold)
}
result := make([]string, layout.height)
for row, cells := range canvas {
@@ -267,7 +307,7 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
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)
result[row] = left + stageTitle(node.key, title, node.key == selected, graph) + right
result[row] = left + appearance.title(node.key, title, node.key == selected, graph) + right
}
return result
}