Add stage execution limits and result-first workflow views

This commit is contained in:
2026-10-10 03:03:46 +01:00
parent 7b10e3889e
commit a66d540125
35 changed files with 1392 additions and 93 deletions
+12 -3
View File
@@ -47,12 +47,15 @@ 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),
lipgloss.NewStyle().Foreground(themeMuted).Render("Pipeline · Version · Outcome · Duration")}
lipgloss.NewStyle().Foreground(themeMuted).Render("Outcome · Result · Completed work")}
if len(m.runs) == 0 {
runs = append(runs, "No runs yet.")
}
for _, r := range m.runs[:min(8, len(m.runs))] {
runs = append(runs, lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("#%d %s", r.ID, r.Name))+fmt.Sprintf(" · v%d · %s · %s", r.Version, m.progress(r.Status), runDuration(r.CreatedAt, r.FinishedAt)), lipgloss.NewStyle().Foreground(themeMuted).Render(" Started: "+dateLabel(r.CreatedAt)))
runs = append(runs, lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("#%d %s", r.ID, r.Name))+fmt.Sprintf(" · v%d · %s · %s", r.Version, m.progress(r.Status), runDuration(r.CreatedAt, r.FinishedAt)), " "+resultLabel(r))
if r.CompletedSteps > 0 {
runs = append(runs, fmt.Sprintf(" %d completed visits", r.CompletedSteps))
}
if r.CurrentStage != "" && (r.Status == "running" || r.Status == "queued") {
runs = append(runs, " Stage: "+r.CurrentStage)
}
@@ -70,7 +73,13 @@ func (m Model) homeLines() []string {
for _, p := range m.pipelines {
lines = append(lines,
lipgloss.NewStyle().Bold(true).Render(p.Name)+lipgloss.NewStyle().Foreground(themeMuted).Render(fmt.Sprintf(" v%d · %d stages", p.Version, p.Stages)),
lipgloss.NewStyle().Foreground(themeMuted).Render(" Created: "+dateLabel(p.CreatedAt)), lipgloss.NewStyle().Foreground(themeMuted).Render(" Updated: "+dateLabel(p.UpdatedAt)))
lipgloss.NewStyle().Foreground(themeMuted).Render(" Updated: "+dateLabel(p.UpdatedAt)))
if r := m.latestPipelineRun(p.ID, 0); r != nil {
lines = append(lines, fmt.Sprintf(" Last run #%d · v%d · %s", r.ID, r.Version, m.progress(r.Status)), " "+resultLabel(*r))
} else {
lines = append(lines, " Not run yet · no recorded results")
}
lines = append(lines, lipgloss.NewStyle().Foreground(themeMuted).Render(" Created: "+dateLabel(p.CreatedAt)))
if m.usage != nil {
for _, u := range m.usage.Pipelines {
if u.PipelineID == p.ID {
+2 -2
View File
@@ -338,8 +338,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
accepted := m.runOpen && msg.RunDetail != nil && ((msg.Type == protocol.Run && msg.RunDetail.ID == m.requestedRunID) || (msg.Type == protocol.RunStarted && msg.ID == m.runStartRequest))
if accepted {
if m.runDetail == nil {
m.runGraphFocus = true
m.runDetailFocus = false
m.runGraphFocus = false
m.runDetailFocus = true
m.runGraphTop, m.runGraphPan = 0, 0
}
if msg.Type == protocol.RunStarted {
+18 -2
View File
@@ -10,6 +10,7 @@ import (
"github.com/charmbracelet/x/ansi"
"git.a-wan.net/alan/pipelines/internal/protocol"
stageconfig "git.a-wan.net/alan/pipelines/internal/stage"
)
type paneGeometry struct {
@@ -17,7 +18,7 @@ type paneGeometry struct {
}
func (m Model) pipelineGeometry(height int) paneGeometry {
remaining := max(0, height-3)
remaining := max(0, height-3-len(m.pipelineResultLines()))
if remaining >= 15 {
graph := remaining * 3 / 4
if m.stageFocus {
@@ -122,7 +123,9 @@ func (m Model) pipelineToolbar() []string {
meta += " · historical, inactive"
}
}
return []string{buttons, meta, ""}
lines := []string{buttons}
lines = append(lines, m.pipelineResultLines()...)
return append(lines, meta, "")
}
func (m Model) pipelineView(height int) string {
@@ -284,6 +287,19 @@ func (m Model) stageFields() []stageField {
for _, k := range keys {
configs = append(configs, lipgloss.NewStyle().Foreground(themeMuted).Render(k+" ")+stage.Configs[k])
}
if stage.Configs["timeout"] == "" {
configs = append(configs, fmt.Sprintf("timeout %s (default per attempt)", stageconfig.DefaultTimeout))
}
if stage.Type == "" || stage.Type == stageconfig.ModelType {
if stage.Configs["retries"] == "" {
configs = append(configs, fmt.Sprintf("retries %d (default)", stageconfig.DefaultRetries))
}
for _, key := range []string{"budget_usd", "budget_tokens"} {
if stage.Configs[key] == "" {
configs = append(configs, key+" unlimited")
}
}
}
var edges []graphEdge
maxLabel := 0
for _, edge := range graphEdges(m.detail.Graph) {
+131
View File
@@ -0,0 +1,131 @@
package tui
import (
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func resultLabel(r protocol.RunSummary) string {
preview := ansi.Strip(r.ResultPreview)
if r.Status == "succeeded" {
if preview != "" {
return "Result: " + preview
}
return "Finished · no result recorded"
}
if r.Diagnostic != "" {
return "Stopped: " + ansi.Strip(r.Diagnostic)
}
if preview != "" {
return "Latest output: " + preview
}
if r.Status == "running" || r.Status == "queued" {
return "In progress · awaiting stage output"
}
return "No result recorded"
}
func (m Model) latestPipelineRun(id int64, version int) *protocol.RunSummary {
var latest *protocol.RunSummary
for i := range m.runs {
r := &m.runs[i]
if r.PipelineID == id && (version == 0 || r.Version == version) && (latest == nil || r.ID > latest.ID) {
latest = r
}
}
return latest
}
func (m Model) pipelineResultLines() []string {
if m.detail == nil {
return nil
}
r := m.latestPipelineRun(m.detail.ID, m.detail.Version)
if r == nil {
return []string{"Results · This version has not run yet. No accomplishments recorded."}
}
lines := []string{fmt.Sprintf("Results · run #%d · %s · %d completed visits · %s", r.ID, ansi.Strip(m.progress(r.Status)), r.CompletedSteps, runDuration(r.CreatedAt, r.FinishedAt)), resultLabel(*r)}
if r.Status != "succeeded" && r.ResultPreview != "" && r.Diagnostic != "" {
lines = append(lines, "Partial output: "+ansi.Strip(r.ResultPreview))
}
return lines
}
func runResultLines(r *protocol.RunDetail) []string {
lines := []string{}
if r.Diagnostic != "" {
lines = append(lines, "Stopped: "+ansi.Strip(r.Diagnostic))
}
if r.Status == "succeeded" {
if preview := protocol.OutputPreview(r.Output); preview != "" {
lines = append(lines, "Result: "+ansi.Strip(preview))
} else {
lines = append(lines, "Finished · no result recorded")
}
} else {
if r.Status == "running" || r.Status == "queued" {
lines = append(lines, "In progress · final result pending")
}
for i := len(r.Steps) - 1; i >= 0; i-- {
if r.Steps[i].Status == "completed" {
if preview := protocol.OutputPreview(r.Steps[i].Output); preview != "" {
lines = append(lines, "Latest completed output ("+r.Steps[i].Stage+"): "+ansi.Strip(preview))
}
break
}
}
}
completed := 0
failed := 0
for _, s := range r.Steps {
if s.Status == "completed" {
completed++
}
if s.Status == "failed" {
failed++
}
}
lines = append(lines, fmt.Sprintf("Progress: %d completed visits · %d failed · %d recorded", completed, failed, len(r.Steps)))
if r.CurrentStage != "" && (r.Status == "running" || r.Status == "queued") {
lines = append(lines, "Working on: "+r.CurrentStage)
}
return lines
}
func completedWorkLines(r *protocol.RunDetail) []string {
var lines []string
for _, s := range r.Steps {
if s.Status != "completed" {
continue
}
line := fmt.Sprintf("%d. %s · %s", s.Sequence, s.Stage, s.Outcome)
if preview := protocol.OutputPreview(s.Output); preview != "" {
line += " — " + ansi.Strip(preview)
} else {
line += " — no output recorded"
}
lines = append(lines, line)
}
if len(lines) == 0 {
lines = append(lines, "No completed stage output yet.")
}
return append([]string{"Completed stage outputs (reported, not independently verified):"}, lines...)
}
func resultOutputLines(r *protocol.RunDetail) []string {
if len(r.Output) > 0 {
return valueLines(r.Output)
}
for i := len(r.Steps) - 1; i >= 0; i-- {
if r.Steps[i].Status == "completed" && len(r.Steps[i].Output) > 0 {
return append([]string{"Partial output · " + r.Steps[i].Stage + " (not a final result)", ""}, valueLines(r.Steps[i].Output)...)
}
}
if strings.TrimSpace(r.Diagnostic) != "" {
return []string{r.Diagnostic}
}
return []string{"No output recorded yet."}
}
+76
View File
@@ -0,0 +1,76 @@
package tui
import (
"context"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func TestHomeAndPipelineShowRecordedResultsForExactVersion(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 140, 48
m.loaded = true
m.pipelines = []protocol.PipelineSummary{{ID: 1, Name: "Maintenance", Version: 2, Stages: 2}}
m.runs = []protocol.RunSummary{
{ID: 12, PipelineID: 1, Version: 2, Name: "Maintenance", Status: "succeeded", ResultPreview: "Added regression coverage", CompletedSteps: 2},
{ID: 11, PipelineID: 1, Version: 1, Status: "succeeded", ResultPreview: "Created the initial report", CompletedSteps: 1},
}
view := ansi.Strip(m.View())
for _, want := range []string{"Result: Added regression coverage", "2 completed visits", "Last run #12"} {
if !strings.Contains(view, want) {
t.Fatal("home missing result", want, view)
}
}
m.detail = &protocol.PipelineDetail{PipelineSummary: m.pipelines[0], LatestVersion: 2, Graph: protocol.Graph{Stages: []protocol.Stage{{Key: "worker", Edges: map[string]string{"success": protocol.SuccessEnd}}}}}
view = ansi.Strip(m.pipelineView(40))
if !strings.Contains(view, "Added regression coverage") || strings.Index(view, "Results") > strings.Index(view, "Graph") {
t.Fatal("pipeline does not lead with results", view)
}
m.detail.Version = 1
view = ansi.Strip(m.pipelineView(40))
if !strings.Contains(view, "Created the initial report") || strings.Contains(view, "Added regression coverage") {
t.Fatal("pipeline mixed version results", view)
}
m.detail.Version = 3
if view = ansi.Strip(m.pipelineView(40)); !strings.Contains(view, "has not run yet") || strings.Contains(view, "Added regression coverage") {
t.Fatal("unexecuted version invented results", view)
}
}
func TestRunLeadsWithResultAndPreservesPartialAccomplishments(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 120, 48
m.runDetailFocus = true
r := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Name: "Maintenance", Status: "failed", Diagnostic: "Verification timed out"}, Steps: []protocol.RunStep{
{Sequence: 1, Stage: "implement", Status: "completed", Outcome: "success", Output: map[string]any{"summary": "Updated the layout", "artifacts": []string{"screen.go"}}},
{Sequence: 2, Stage: "verify", Status: "failed", Diagnostic: "Verification timed out"},
}}
m.runDetail = r
view := ansi.Strip(m.runsView(44))
for _, want := range []string{"Stopped: Verification timed out", "Latest completed output (implement): Updated the layout", "Partial output", "screen.go"} {
if !strings.Contains(view, want) {
t.Fatal("partial result hidden", want, view)
}
}
if strings.Index(view, "Updated the layout") > strings.Index(view, "Run graph") {
t.Fatal("graph precedes result")
}
lines := ansi.Strip(strings.Join(m.runSectionLines(100), "\n"))
if !strings.Contains(lines, "1. implement · success — Updated the layout") || strings.Index(lines, "[o]") > strings.Index(lines, "[i]") {
t.Fatal("recorded accomplishments hidden behind inputs", lines)
}
r.Status = "succeeded"
r.Diagnostic = ""
r.Output = map[string]any{"summary": "Layout verified", "report": "Checks passed", "artifacts": []string{"screen.go"}}
if lines = ansi.Strip(strings.Join(m.runSectionLines(100), "\n")); !strings.Contains(lines, "Result: Layout verified") {
t.Fatal("final result not prominent", lines)
}
r.Output = nil
r.Steps = nil
if lines = ansi.Strip(strings.Join(m.runSectionLines(100), "\n")); !strings.Contains(lines, "no result recorded") || strings.Contains(lines, "Layout verified") {
t.Fatal("empty success fabricated work", lines)
}
}
+37 -9
View File
@@ -9,6 +9,7 @@ import (
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
@@ -299,6 +300,11 @@ func evidenceLines(step protocol.RunStep) []string {
return append(lines, "No captured tool evidence yet.")
}
var audit struct {
Limits *struct {
Timeout string `json:"timeout"`
Retries int `json:"retries"`
Budget stage.BudgetSnapshot `json:"budget"`
} `json:"stage_limits"`
Data []json.RawMessage `json:"data"`
FormatRepairs []struct {
Method string `json:"method"`
@@ -347,6 +353,24 @@ func evidenceLines(step protocol.RunStep) []string {
for _, repair := range audit.FormatRepairs {
lines = append(lines, fmt.Sprintf("JSON format repair: %s · accepted: %t", repair.Method, repair.Accepted), repair.Diagnostic)
}
if limits := audit.Limits; limits != nil {
b := limits.Budget
lines = append(lines, fmt.Sprintf("Timeout per attempt: %s · Retries: %d · Attempts: %d", limits.Timeout, limits.Retries, b.Attempts))
if b.LimitUSD > 0 {
used := "unknown"
if b.USDKnown {
used = fmt.Sprintf("$%.6f", b.UsedUSD)
}
lines = append(lines, fmt.Sprintf("USD budget: %s / $%.6f", used, b.LimitUSD))
}
if b.LimitTokens > 0 {
used := "unknown"
if b.TokensKnown {
used = fmt.Sprint(b.UsedTokens)
}
lines = append(lines, fmt.Sprintf("Token budget: %s / %d", used, b.LimitTokens))
}
}
count := 0
for i := len(audit.Data) - 1; i >= 0; i-- {
var message struct {
@@ -390,10 +414,7 @@ func (m Model) runSectionLines(width int) []string {
r := m.runDetail
titles := []string{"Summary", "Input", "Output", "Tool evidence", "Metadata"}
shortcuts := []string{"s", "i", "o", "t", "m"}
summary := []string{"Status: " + m.progress(r.Status), "Outcome: " + r.Outcome, fmt.Sprintf("Stages: %d · Current: %s", len(r.Steps), r.CurrentStage), "Started: " + dateLabel(r.CreatedAt), "Finished: " + dateLabel(r.FinishedAt), "Duration: " + runDuration(r.CreatedAt, r.FinishedAt)}
if r.Diagnostic != "" {
summary = append(summary, lipgloss.NewStyle().Foreground(themeError).Render(r.Diagnostic))
}
summary := append([]string{"Status: " + m.progress(r.Status)}, runResultLines(r)...)
if m.runError != "" {
summary = append(summary, "Request error: "+m.runError)
}
@@ -401,17 +422,22 @@ func (m Model) runSectionLines(width int) []string {
if len(r.WritePaths) > 0 {
editScope = strings.Join(r.WritePaths, ", ")
}
content := [][]string{summary, valueLines(r.Input), valueLines(r.Output), {"Select a stage to inspect its tool calls."}, {"Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, fmt.Sprintf("Shell/edit enabled: %t", r.AllowTools), "Stage tools: defined by the pinned pipeline version", "Edit scope: " + editScope}}
output := resultOutputLines(r)
output = append(output, "", strings.Join(completedWorkLines(r), "\n"))
content := [][]string{summary, valueLines(r.Input), output, {"Select a stage to inspect its tool calls."}, {"Started: " + dateLabel(r.CreatedAt), "Finished: " + dateLabel(r.FinishedAt), "Duration: " + runDuration(r.CreatedAt, r.FinishedAt), "Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, fmt.Sprintf("Shell/edit enabled: %t", r.AllowTools), "Stage tools: defined by the pinned pipeline version", "Edit scope: " + editScope}}
if r.RetryOf > 0 {
content[4] = append(content[4], fmt.Sprintf("Retry of run #%d", r.RetryOf))
}
if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) {
step := r.Steps[m.runStepIndex-1]
summary = []string{"Status: " + m.progress(m.stepProgressStatus(step)), "Route: " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target, "Started: " + dateLabel(step.StartedAt), "Finished: " + dateLabel(step.FinishedAt), "Duration: " + runDuration(step.StartedAt, step.FinishedAt)}
summary = []string{"Status: " + m.progress(m.stepProgressStatus(step)), "Route: " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target}
if preview := protocol.OutputPreview(step.Output); preview != "" {
summary = append(summary, "Reported output: "+ansi.Strip(preview))
}
if step.Diagnostic != "" {
summary = append(summary, lipgloss.NewStyle().Foreground(themeError).Render(step.Diagnostic))
}
content = [][]string{summary, valueLines(step.Input), valueLines(step.Output), evidenceLines(step), {"Session: " + step.SessionID, fmt.Sprintf("Agent active: %t", step.AgentActive), fmt.Sprintf("Attempt sequence: %d", step.Sequence)}}
content = [][]string{summary, valueLines(step.Input), valueLines(step.Output), evidenceLines(step), {"Started: " + dateLabel(step.StartedAt), "Finished: " + dateLabel(step.FinishedAt), "Duration: " + runDuration(step.StartedAt, step.FinishedAt), "Session: " + step.SessionID, fmt.Sprintf("Agent active: %t", step.AgentActive), fmt.Sprintf("Attempt sequence: %d", step.Sequence)}}
for _, receipt := range step.Notifications {
line := "Notification: " + receipt.Destination + " · " + receipt.Status
if receipt.Filename != "" {
@@ -430,7 +456,8 @@ func (m Model) runSectionLines(width int) []string {
}
}
var lines []string
for i, title := range titles {
for _, i := range []int{0, 2, 1, 3, 4} {
title := titles[i]
marker := "▾"
if m.runSectionClosed(i) {
marker = "▸"
@@ -529,11 +556,12 @@ func (m Model) runsDetailsView(height int) string {
rows = append(rows, "Search: "+m.runSearch.View())
}
runs := m.visibleRuns()
start, end := selectionWindow(len(runs), m.runIndex, max(1, height-4-len(rows)))
start, end := selectionWindow(len(runs), m.runIndex, max(1, (height-4-len(rows))/2))
for i := start; i < end; i++ {
r := runs[i]
text := fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Name, r.Version, m.progress(r.Status), dateLabel(r.FinishedAt))
rows = append(rows, menuOption(text, i == m.runIndex))
rows = append(rows, " "+ansi.Truncate(resultLabel(r), max(1, m.width-6), "…"))
}
if len(runs) == 0 {
rows = append(rows, "No runs yet.")
+1 -1
View File
@@ -97,7 +97,7 @@ func (m Model) runsView(height int) string {
}
graph := m.runGraphPanel(graphHeight, top, pan)
details := m.runsDetailsView(detailHeight)
return fitBlock(strings.Split(graph+"\n"+details, "\n"), m.width, height)
return fitBlock(strings.Split(details+"\n"+graph, "\n"), m.width, height)
}
func (m Model) runPaneHeights(height int) (int, int) {
+2 -2
View File
@@ -103,8 +103,8 @@ func TestRunPathUsesSharedRendererAndRecordedRoutesWithRepeatedVisits(t *testing
t.Fatal("run graph diverged from common renderer")
}
view := ansi.Strip(m.runsView(36))
if strings.Index(view, "Run graph") < 0 || strings.Index(view, "Run graph") > strings.Index(view, "Run overview") || !strings.Contains(view, "3. plan (running)") {
t.Fatal("run graph missing above details or current visit not visible", view)
if strings.Index(view, "Run graph") < 0 || strings.Index(view, "Run graph") < strings.Index(view, "Run overview") || !strings.Contains(view, "3. plan (running)") {
t.Fatal("run graph missing below results or current visit not visible", view)
}
refreshed := *m.runDetail
refreshed.Steps = append([]protocol.RunStep(nil), m.runDetail.Steps...)
+7 -2
View File
@@ -18,8 +18,13 @@ func TestRunPanesExpandWithTabFocus(t *testing.T) {
updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run}))
m = updated.(Model)
graph, details := m.runPaneHeights(44)
if !m.runGraphFocus || graph <= details || graph+details != 44 {
t.Fatal("new run did not prioritize graph", graph, details)
if !m.runDetailFocus || m.runGraphFocus || details <= graph || graph+details != 44 {
t.Fatal("new run did not prioritize results", graph, details)
}
m = runKey(m, "tab")
graph, details = m.runPaneHeights(44)
if !m.runGraphFocus || graph <= details {
t.Fatal("graph focus did not expand")
}
graphPage := m.runPageSize()
m = runKey(m, "tab")
+2 -2
View File
@@ -195,8 +195,8 @@ func TestRunSectionsOrderTitleAndNumberSelection(t *testing.T) {
m := runInspectionModel()
m = runKey(m, "1")
text := ansi.Strip(strings.Join(m.runSectionLines(70), "\n"))
if strings.Index(text, "Input") > strings.Index(text, "Output") {
t.Fatal("input must precede output")
if strings.Index(text, "Output") > strings.Index(text, "Input") {
t.Fatal("output must precede input")
}
if m.runSectionClosed(2) || !m.runSectionClosed(1) {
t.Fatal("output should remain visible; input initially collapsed")