Merge lane-go: titles, verdicts, human stage, line result format, stale-client guard

Integrates nine commits of reviewed work from the lane-go branch after the
automated resolver failed on this merge five times (each attempt dying on the
malformed-result defect whose fix is contained in this same merge).

Integration decisions:
- Search: kept main's shipped design (Store.Search + SearchResponse.Results) and
  dropped lane-go's parallel, older attempt (an unused Message.Matches field, an
  absent runs.search, and two partial TUI plumbing blocks). lane-go itself did not
  compile: protocol.SearchMatch was undefined and model.go referenced searchNav,
  requestSearch and applyRunNav, which exist nowhere. Those partial TUI blocks are
  removed; the queued TUI omni-search item will implement the surface properly on
  main's design.
- Both sides' additions are kept where they are independent: run titles and
  provenance, the human decision stage and its CLI/TUI surface, the derived stage
  verdict, the stale-client guard, the line-oriented result format, and main's
  search command.
- The search key's help label is now "/ omni search"; the two tests asserting the
  old label are updated rather than the label reverted.
- docs/cli.md and the packaged operations reference carry both sides' text.

Verified: go build ./... , go vet ./... and the full go test ./... suite pass.
This commit is contained in:
2026-10-16 22:21:43 +01:00
669 changed files with 7205 additions and 276 deletions
+3 -3
View File
@@ -10,9 +10,9 @@ import (
)
type RunOptions struct {
Pipeline, Prompt, Workspace string
Yes, AllowTools bool
WritePaths []string
Pipeline, Prompt, Title, Workspace string
Yes, AllowTools bool
WritePaths []string
}
func NewRun(ctx context.Context, url string, options RunOptions) Model {
+4
View File
@@ -13,6 +13,8 @@ func (m Model) activeFooter() string {
switch {
case m.editorChecking:
text = "Refreshing published state · draft retained"
case m.decisionOpen:
text = "↑/↓ choose · Tab feedback · Enter decide · Esc cancel"
case m.actionConfirm != nil || m.mutationCommand != nil:
text = "y confirm · n/Esc cancel · j/k read"
case m.draftDeletingPath != "":
@@ -59,6 +61,8 @@ func (m Model) activeFooter() string {
switch {
case m.editorChecking:
text = "Refreshing · draft retained"
case m.decisionOpen:
text = "Esc cancel · Enter decide · ↑↓ select"
case m.actionConfirm != nil || m.mutationCommand != nil:
text = "Esc cancel · y confirm · j/k read"
case m.draftDeletingPath != "":
+5 -2
View File
@@ -98,12 +98,15 @@ func (m Model) homeLines() []string {
limit = 2
}
for _, r := range m.runs[:min(limit, len(m.runs))] {
runs = append(runs, bar(fmt.Sprintf("#%d %s", r.ID, r.Name), m.progress(r.Status), max(1, panelWidth-4), false))
runs = append(runs, bar(fmt.Sprintf("#%d %s", r.ID, r.Label()), m.progress(r.Status), max(1, panelWidth-4), false))
runs = append(runs, previewRows(resultLabel(r), max(1, panelWidth-4), 3)...)
runs = append(runs, lipgloss.NewStyle().Foreground(themeMuted).Render(fmt.Sprintf("v%d · %d completed visits · %s", r.Version, r.CompletedSteps, runDuration(r.CreatedAt, r.FinishedAt))))
if r.CurrentStage != "" && (r.Status == "running" || r.Status == "queued") {
runs = append(runs, "Working on "+r.CurrentStage)
}
if r.Status == protocol.RunStatusWaiting {
runs = append(runs, "Waiting on a person · stage "+r.CurrentStage)
}
runs = append(runs, "")
}
if len(m.runs) > limit {
@@ -123,7 +126,7 @@ func (m Model) homeLines() []string {
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)))
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)))
lines = append(lines, fmt.Sprintf("Last run #%d · %s · v%d · %s", r.ID, r.Label(), r.Version, m.progress(r.Status)))
lines = append(lines, previewRows(resultLabel(*r), max(1, pipelineWidth-4), 2)...)
} else {
lines = append(lines, "Not run yet · no recorded results")
+1 -1
View File
@@ -143,7 +143,7 @@ func TestHomeOnlyAdvertisesSearchAndCommands(t *testing.T) {
m.usage = &protocol.UsageStats{}
}
view := ansi.Strip(m.View())
for _, hint := range []string{"/ search", ": commands"} {
for _, hint := range []string{"/ omni search", ": commands"} {
if !strings.Contains(view, hint) {
t.Fatal("missing home hint", hint, view)
}
+164
View File
@@ -0,0 +1,164 @@
package tui
import (
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
)
// lastWaitingStep returns the most recent step a run is waiting on (the last
// waiting step by sequence), or false when no step is waiting. The decision
// overlay and the run summary both read it, so the scan lives once.
func lastWaitingStep(r *protocol.RunDetail) (protocol.RunStep, bool) {
for i := len(r.Steps) - 1; i >= 0; i-- {
if r.Steps[i].Status == protocol.StepStatusWaiting {
return r.Steps[i], true
}
}
return protocol.RunStep{}, false
}
// waitingStage returns the stage the open run is waiting on plus its recorded
// prompt and selectable options. It prefers the self-contained evidence on the
// waiting step and falls back to the pinned graph's edges when a step recorded
// no options.
func (m Model) waitingStage() (string, []string, string) {
if m.runDetail == nil {
return "", nil, ""
}
if step, ok := lastWaitingStep(m.runDetail); ok {
return step.Stage, protocol.WaitingOptions(step.Output), protocol.WaitingPrompt(step.Output)
}
key := m.runDetail.CurrentStage
for _, declared := range m.runDetail.Graph.Stages {
if declared.Key == key {
return key, stage.HumanOptions(declared.Edges), declared.Prompt
}
}
return key, nil, ""
}
func (m Model) openDecision() (tea.Model, tea.Cmd) {
if m.runDetail == nil || m.runDetail.Status != protocol.RunStatusWaiting {
m.runError = "This run is not waiting for a decision."
return m, nil
}
key, options, _ := m.waitingStage()
if len(options) == 0 {
m.runError = "No selectable options recorded for the waiting stage."
return m, nil
}
m.decisionOpen = true
m.decisionRunID = m.runDetail.ID
m.decisionStage = key
m.decisionOptions = options
m.decisionIndex = 0
m.decisionFeedback = newInput()
m.decisionFeedback.Placeholder = "Optional feedback"
m.decisionFeedback.Width = max(1, min(60, m.width-12))
m.decisionFeedbackFocus = false
return m, nil
}
func (m *Model) closeDecision() {
m.decisionOpen = false
m.decisionRunID = 0
m.decisionStage = ""
m.decisionOptions = nil
m.decisionIndex = 0
m.decisionFeedback = newInput()
m.decisionFeedbackFocus = false
}
func (m Model) updateDecision(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "esc":
m.closeDecision()
return m, nil
case "tab":
m.decisionFeedbackFocus = !m.decisionFeedbackFocus
if m.decisionFeedbackFocus {
return m, m.decisionFeedback.Focus()
}
m.decisionFeedback.Blur()
return m, nil
case "f":
if !m.decisionFeedbackFocus {
m.decisionFeedbackFocus = true
return m, m.decisionFeedback.Focus()
}
case "up", "k":
if !m.decisionFeedbackFocus {
m.decisionIndex = max(0, m.decisionIndex-1)
return m, nil
}
case "down", "j":
if !m.decisionFeedbackFocus {
m.decisionIndex = min(m.decisionIndex+1, max(0, len(m.decisionOptions)-1))
return m, nil
}
case "enter":
if len(m.decisionOptions) == 0 {
return m, nil
}
option := m.decisionOptions[min(m.decisionIndex, len(m.decisionOptions)-1)]
feedback := strings.TrimSpace(m.decisionFeedback.Value())
request := protocol.Message{Type: protocol.DecideRun, RunID: m.decisionRunID, Stage: m.decisionStage, Option: option, Feedback: feedback}
m.closeDecision()
return m.runRequest(request)
}
if m.decisionFeedbackFocus {
var cmd tea.Cmd
m.decisionFeedback, cmd = m.decisionFeedback.Update(msg)
return m, cmd
}
return m, nil
}
func (m Model) decisionView(height int) string {
title := fmt.Sprintf("Decide %s · run #%d", m.decisionStage, m.decisionRunID)
intro := "Choose where the run goes next. The choice and feedback are recorded as the stage's evidence."
if m.width < 65 {
intro = "Choose where the run goes next."
}
// Size the option window to the panel body so every shown paragraph fits and
// the selected option is never clipped: each option costs a line plus a
// separator, and the feedback line always fits. The count of shown options
// goes in the controls, so a windowed list still says more exist.
dialogWidth := min(m.width, 76)
inner := max(1, dialogWidth-4)
introLines := len(strings.Split(ansi.Wrap(intro, inner, ""), "\n"))
capacity := max(1, (height-4-introLines)/2-1)
count := len(m.decisionOptions)
start, end := selectionWindow(count, m.decisionIndex, capacity)
paragraphs := []string{intro}
for i := start; i < end; i++ {
marker := " "
if i == m.decisionIndex {
marker = " › "
}
paragraphs = append(paragraphs, marker+m.decisionOptions[i])
}
paragraphs = append(paragraphs, "Feedback: "+m.decisionFeedback.View())
controls := "↑/↓ choose · Tab feedback · Enter decide · Esc cancel"
if end-start < count {
controls += fmt.Sprintf(" · %d/%d", end-start, count)
}
if m.width < 65 {
controls = "↑↓ select · Enter decide · Esc"
if end-start < count {
controls += fmt.Sprintf(" · %d/%d", end-start, count)
}
}
if m.decisionFeedbackFocus {
controls = "type feedback · Tab options · Enter decide · Esc cancel"
if m.width < 65 {
controls = "type feedback · Enter decide · Esc"
}
}
return wrappedDialog(m.width, height, 72, title, paragraphs, controls, 0)
}
+137
View File
@@ -0,0 +1,137 @@
package tui
import (
"context"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
)
func decisionModel() Model {
m := New(context.Background(), "")
m.width = 100
m.height = 30
m.runOpen = true
m.keys.runs = true
m.requestedRunID = 8
m.runDetail = &protocol.RunDetail{
RunSummary: protocol.RunSummary{ID: 8, Name: "release", Version: 1, Status: protocol.RunStatusWaiting, CurrentStage: "gate"},
Steps: []protocol.RunStep{{
Sequence: 1, Stage: "gate", Status: protocol.StepStatusWaiting,
Output: protocol.NewWaitingEvidence("Approve the release?", []string{"go", "halt"}),
}},
}
return m
}
func TestWaitingRunRendersPromptAndOptions(t *testing.T) {
m := decisionModel()
text := ansi.Strip(strings.Join(m.runSectionLines(m.runDetailWidth()), "\n"))
for _, want := range []string{"Waiting for a person · stage gate", "Approve the release?", "Options: go, halt"} {
if !strings.Contains(text, want) {
t.Fatalf("waiting run view missing %q:\n%s", want, text)
}
}
detail := ansi.Strip(m.runsDetailsView(24))
if !strings.Contains(detail, "Waiting for a person") {
t.Fatalf("run detail omitted the waiting banner:\n%s", detail)
}
}
func TestDecisionOverlaySelectsAndEmits(t *testing.T) {
m := decisionModel()
updated, _ := m.openDecision()
m = updated.(Model)
if !m.decisionOpen || m.decisionStage != "gate" || strings.Join(m.decisionOptions, ",") != "go,halt" {
t.Fatalf("overlay did not open with the recorded options: %+v", m.decisionOptions)
}
if view := ansi.Strip(m.decisionView(24)); !strings.Contains(view, "Decide gate") || !strings.Contains(view, "halt") {
t.Fatalf("overlay view missing the choice:\n%s", view)
}
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown})
m = updated.(Model)
if m.decisionIndex != 1 {
t.Fatalf("down did not move the selection: %d", m.decisionIndex)
}
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyTab})
m = updated.(Model)
if !m.decisionFeedbackFocus {
t.Fatal("Tab did not focus the feedback field")
}
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyEsc})
m = updated.(Model)
if m.decisionOpen {
t.Fatal("Esc did not close the overlay")
}
// Enter emits a DecideRun request; with no connection the send path records
// the attempt and the overlay closes.
updated, _ = m.openDecision()
m = updated.(Model)
m.decisionFeedback.SetValue("looks good")
before := len(m.lines)
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if m.decisionOpen {
t.Fatal("Enter did not close the overlay")
}
if len(m.lines) == before {
t.Fatal("Enter did not attempt to send the decision")
}
if !strings.Contains(strings.Join(m.lines, "\n"), "not connected") {
t.Fatalf("decision path did not run: %v", m.lines)
}
}
// TestDecisionOverlayKeepsSelectionVisibleAtNarrowViewport proves the overlay
// windows its option list like the palette: at the smallest reviewed viewport
// the selected option stays visible with its marker and a count says more exist.
func TestDecisionOverlayKeepsSelectionVisibleAtNarrowViewport(t *testing.T) {
m := decisionModel()
m.width = 40
m.height = 16
m.runDetail.Steps[0].Output = protocol.NewWaitingEvidence("Approve the release?", []string{"abort", "deploy", "revise"})
updated, _ := m.openDecision()
m = updated.(Model)
// Move onto the option a fixed, unwindowed list would clip at this viewport.
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown})
m = updated.(Model)
updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown})
m = updated.(Model)
view := ansi.Strip(m.View())
if !strings.Contains(view, "› revise") {
t.Fatalf("selected option is not visible with a marker at 40x16:\n%s", view)
}
if !strings.Contains(view, "2/3") {
t.Fatalf("option count affordance missing at 40x16:\n%s", view)
}
if strings.Contains(view, "Enter d…") {
t.Fatalf("controls are still truncated at 40x16:\n%s", view)
}
}
// TestDecidedHumanStepRendersNeutralFeedback locks the fix for the review
// finding: a completed decision shows its feedback as a normal output field,
// never as the error-style "Stopped:" line reserved for real stops.
func TestDecidedHumanStepRendersNeutralFeedback(t *testing.T) {
m := decisionModel()
m.runDetail.Status = "succeeded"
output := map[string]any{"option": "go", "feedback": "looks good"}
m.runDetail.Steps[0] = protocol.RunStep{
Sequence: 1, Stage: "gate", Status: "completed", Outcome: "go", Target: "worker",
Output: output,
Verdict: protocol.NewStageVerdict("go", "worker", output, nil, "", ""),
}
m.runStepIndex = 1
view := ansi.Strip(strings.Join(m.runSectionLines(m.runDetailWidth()), "\n"))
if strings.Contains(view, "Stopped:") {
t.Fatalf("a deliberate decision must not render as a stop:\n%s", view)
}
if !strings.Contains(view, "looks good") {
t.Fatalf("decision feedback is not visible:\n%s", view)
}
}
+6 -3
View File
@@ -15,8 +15,9 @@ import (
)
type draftValidationMsg struct {
path string
err error
path string
notices []string
err error
}
func (m Model) openDrafts() (tea.Model, tea.Cmd) {
@@ -157,8 +158,10 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
return draftValidationMsg{path: d.Path, err: err}
}
defer c.Close()
sink := &noticeSink{}
c.Report(sink.report)
_, err = c.Call(ctx, protocol.Message{Type: protocol.Validate, Source: source})
return draftValidationMsg{path: d.Path, err: err}
return draftValidationMsg{path: d.Path, notices: sink.drain(), err: err}
}
}
}
+50 -36
View File
@@ -16,71 +16,85 @@ type editorPublicationMsg struct {
pipelines []protocol.PipelineSummary
detail *protocol.PipelineDetail
published bool
notices []string
err error
}
func checkEditorPublication(ctx context.Context, endpoint string, edit editedMsg, generation uint64) tea.Cmd {
return func() tea.Msg {
result := editorPublicationMsg{edit: edit, generation: generation}
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
c, err := client.Open(ctx, endpoint)
return publicationCheck(ctx, endpoint, edit, generation)
}
}
// publicationCheck runs the publication comparison for one editor submission.
// The named result lets the deferred hook attach any build/protocol notices
// from the short-lived client to every return path.
func publicationCheck(ctx context.Context, endpoint string, edit editedMsg, generation uint64) (result editorPublicationMsg) {
result = editorPublicationMsg{edit: edit, generation: generation}
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
c, err := client.Open(ctx, endpoint)
if err != nil {
result.err = err
return result
}
defer c.Close()
sink := &noticeSink{}
c.Report(sink.report)
// Surface any build/protocol notice through the shared TUI notice path
// rather than dropping it for this short-lived client.
defer func() { result.notices = sink.drain() }()
list, err := c.Call(ctx, protocol.Message{Type: protocol.List})
if err != nil {
result.err = err
return result
}
result.pipelines = list.Pipelines
for _, p := range list.Pipelines {
if p.Name != strings.TrimSpace(edit.name) {
continue
}
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID})
if err != nil {
result.err = err
return result
}
defer c.Close()
list, err := c.Call(ctx, protocol.Message{Type: protocol.List})
if err != nil {
result.err = err
result.detail = response.Detail
if result.detail == nil {
result.err = fmt.Errorf("server returned no pipeline detail")
return result
}
result.pipelines = list.Pipelines
for _, p := range list.Pipelines {
if p.Name != strings.TrimSpace(edit.name) {
if result.detail.Source == edit.source {
result.published = true
return result
}
// If another version was published afterward, the editor's submitted
// source still must not be offered for duplicate submission. Only
// inspect versions newer than this draft's immutable starting point.
for _, v := range result.detail.Versions {
if v.Version <= edit.baseVersion || v.Version == result.detail.Version {
continue
}
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID})
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID, Version: v.Version})
if err != nil {
result.err = err
return result
}
result.detail = response.Detail
if result.detail == nil {
result.err = fmt.Errorf("server returned no pipeline detail")
return result
}
if result.detail.Source == edit.source {
if response.Detail != nil && response.Detail.Source == edit.source {
result.published = true
return result
}
// If another version was published afterward, the editor's submitted
// source still must not be offered for duplicate submission. Only
// inspect versions newer than this draft's immutable starting point.
for _, v := range result.detail.Versions {
if v.Version <= edit.baseVersion || v.Version == result.detail.Version {
continue
}
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID, Version: v.Version})
if err != nil {
result.err = err
return result
}
if response.Detail != nil && response.Detail.Source == edit.source {
result.published = true
return result
}
}
return result
}
return result
}
return result
}
func (m Model) finishEditorPublication(msg editorPublicationMsg) (tea.Model, tea.Cmd) {
if msg.generation != m.editorCheckGeneration {
return m, nil
}
m.appendNotices(msg.notices)
m.editorChecking = false
if msg.err == nil {
m.pipelines = msg.pipelines
+32
View File
@@ -2,8 +2,11 @@ package tui
import (
"context"
"git.a-wan.net/alan/pipelines/internal/buildinfo"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/server"
"git.a-wan.net/alan/pipelines/internal/wstest"
"net/http/httptest"
"path/filepath"
"strings"
@@ -11,6 +14,35 @@ import (
"time"
)
// TestEditorPublicationSurfacesBuildMismatchNotice proves a short-lived TUI
// command client routes its build/protocol notice through the shared notice
// path instead of dropping it (the artifacts-field regression).
func TestEditorPublicationSurfacesBuildMismatchNotice(t *testing.T) {
stale := buildinfo.Info{Version: "v0-stale-server", Commit: "deadbeef"}
endpoint := wstest.Server(t, func(request protocol.Message) protocol.Message {
switch request.Type {
case protocol.List:
return protocol.Message{Type: protocol.List, Build: &stale, Protocol: protocol.ProtocolVersion,
Pipelines: []protocol.PipelineSummary{{ID: 7, Name: "test", Version: 1}}}
case protocol.GetPipeline:
return protocol.Message{Type: protocol.GetPipeline,
Detail: &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 7, Name: "test", Version: 1}, Source: "published"}}
}
return protocol.Message{Type: protocol.Pong}
})
edit := editedMsg{name: "test", source: "published", baseVersion: 0}
result := publicationCheck(context.Background(), endpoint, edit, 0)
if len(result.notices) != 1 {
t.Fatalf("short-lived client dropped the build mismatch notice: %+v", result.notices)
}
m := New(context.Background(), endpoint)
updated, _ := m.finishEditorPublication(result)
m = updated.(Model)
if !strings.Contains(strings.Join(m.lines, "\n"), "warning:") {
t.Fatalf("notice not routed to the shared TUI notice path: %q", m.lines)
}
}
func TestEditorReturnFindsPublishedVersionAndReloadsLatest(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
+32 -9
View File
@@ -24,7 +24,10 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
)
type connectedMsg struct{ conn *websocket.Conn }
type connectedMsg struct {
conn *websocket.Conn
watch *client.Watch
}
type receivedMsg protocol.Message
type sentMsg struct{ id string }
type errorMsg struct {
@@ -34,6 +37,7 @@ type errorMsg struct {
type socketMsg struct {
conn *websocket.Conn
message protocol.Message
notices []string
}
type reconnectMsg struct{}
@@ -109,6 +113,7 @@ type Model struct {
ctx context.Context
url string
conn *websocket.Conn
watch *client.Watch
status string
nextID uint64
lines []string
@@ -185,6 +190,13 @@ type Model struct {
runGraphFocus bool
runGraphTop int
runGraphPan int
decisionOpen bool
decisionRunID int64
decisionStage string
decisionOptions []string
decisionIndex int
decisionFeedback textinput.Model
decisionFeedbackFocus bool
editorOpen bool
editorInput textinput.Model
editorIndex int
@@ -209,7 +221,7 @@ func New(ctx context.Context, url string) Model {
runSpinner: spinner.New(spinner.WithSpinner(spinner.Spinner{Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, FPS: time.Second / 12}), spinner.WithStyle(lipgloss.NewStyle().Foreground(themeAccent))),
keys: keyMap{
commands: key.NewBinding(key.WithKeys(":"), key.WithHelp(":", "commands")),
search: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "search")),
search: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "omni search")),
create: key.NewBinding(key.WithKeys("n"), key.WithHelp("n", "new pipeline")),
enter: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "continue")),
cancel: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
@@ -236,17 +248,17 @@ func (m Model) connect() tea.Cmd {
<-m.ctx.Done()
conn.CloseNow()
}()
return connectedMsg{conn}
return connectedMsg{conn: conn, watch: &client.Watch{}}
}
}
func (m Model) read() tea.Cmd {
return func() tea.Msg {
response, err := client.Receive(m.ctx, m.conn)
response, notices, err := client.ReceiveNotice(m.ctx, m.conn, m.watch)
if err != nil {
return errorMsg{err: err, conn: m.conn}
}
return socketMsg{conn: m.conn, message: response}
return socketMsg{conn: m.conn, message: response, notices: notices}
}
}
@@ -305,6 +317,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.conn.CloseNow()
}
m.conn = msg.conn
m.watch = msg.watch
m.reconnecting = false
m.status = m.url
if endpoint, err := url.Parse(m.url); err == nil {
@@ -325,6 +338,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.conn != m.conn {
return m, nil
}
// Surface the once-only identity/unrecognized-field notices on the same
// connection without corrupting the TUI layout.
m.appendNotices(msg.notices)
return m.Update(receivedMsg(msg.message))
case receivedMsg:
if msg.Type == protocol.Status && msg.ID == m.statusRequest {
@@ -460,6 +476,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return m, m.read()
case draftValidationMsg:
m.appendNotices(msg.notices)
if len(m.draftItems) > 0 && m.draftItems[m.draftIndex].Path == msg.path {
m.draftError = "Validation passed (structure only)."
if msg.err != nil {
@@ -582,6 +599,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.runForm != 0 {
return m.updateRunForm(msg)
}
if m.decisionOpen {
return m.updateDecision(msg)
}
if m.runOpen && (msg.String() != ":" || m.runSearchOpen) {
return m.updateRuns(msg)
}
@@ -610,11 +630,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.commandIndex = 0
m.commandInput = newInput()
if m.searchOpen {
m.commandInput.Placeholder = "Search pipelines…"
} else {
m.commandInput.Placeholder = ":logs"
m.commandInput.SetValue(":")
m.commandInput.Placeholder = "Type to search…"
return m, m.commandInput.Focus()
}
m.commandInput.Placeholder = ":logs"
m.commandInput.SetValue(":")
return m, m.commandInput.Focus()
case m.homePage() && key.Matches(msg, m.keys.create):
if m.conn == nil {
@@ -784,6 +804,9 @@ func (m Model) View() string {
if m.actionConfirm != nil {
content = m.actionConfirmView(bodyHeight)
}
if m.decisionOpen {
content = m.decisionView(bodyHeight)
}
if m.mutationCommand != nil {
paragraphs := []string{"This opens a new session/editor and may modify a retained draft.", "Published definitions and previous run history are unchanged."}
if strings.Contains(m.mutationTitle, "debugging") {
+1 -1
View File
@@ -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], "/ search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") {
if !strings.HasPrefix(lines[len(lines)-1], "/ omni 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]) != "" {
+44
View File
@@ -0,0 +1,44 @@
package tui
import (
"sync"
"git.a-wan.net/alan/pipelines/internal/buildinfo"
)
// noticeSink collects build/protocol notices from a short-lived client so a TUI
// command can surface them through the shared notice path instead of dropping
// them. It implements client.Reporter.
type noticeSink struct {
mu sync.Mutex
notices []string
}
func (s *noticeSink) report(relationship buildinfo.Relationship) {
if relationship.Message == "" {
return
}
s.mu.Lock()
s.notices = append(s.notices, relationship.Message)
s.mu.Unlock()
}
// drain returns the notices collected so far and resets the sink.
func (s *noticeSink) drain() []string {
s.mu.Lock()
defer s.mu.Unlock()
notices := s.notices
s.notices = nil
return notices
}
// appendNotices is the single TUI notice path: every server relationship or
// unrecognized-field notice is rendered as one warning line, whether it came
// from the long-lived read loop or a short-lived command client.
func (m *Model) appendNotices(notices []string) {
for _, notice := range notices {
if notice != "" {
m.appendLine("warning: " + notice)
}
}
}
+32 -1
View File
@@ -3,6 +3,7 @@ package tui
import (
"fmt"
"maps"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/lipgloss"
@@ -23,6 +24,12 @@ func resultLabel(r protocol.RunSummary) string {
if preview != "" {
return "Latest output: " + preview
}
if r.Status == protocol.RunStatusWaiting {
if r.CurrentStage != "" {
return "Waiting for a person · stage " + r.CurrentStage
}
return "Waiting for a person"
}
if r.Status == "running" || r.Status == "queued" {
return "In progress · awaiting stage output"
}
@@ -48,7 +55,7 @@ func (m Model) pipelineResultLines() []string {
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)}
lines := []string{fmt.Sprintf("Results · run #%d · %s · %s · %d completed visits · %s", r.ID, r.Label(), 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))
}
@@ -60,6 +67,7 @@ func runResultLines(r *protocol.RunDetail) []string {
if r.Diagnostic != "" {
lines = append(lines, "Stopped: "+ansi.Strip(r.Diagnostic))
}
lines = append(lines, waitingLines(r)...)
if r.Status == "succeeded" {
if preview := protocol.OutputPreview(r.Output); preview != "" {
lines = append(lines, "Result: "+ansi.Strip(preview))
@@ -96,6 +104,26 @@ func runResultLines(r *protocol.RunDetail) []string {
return lines
}
// waitingLines renders a run waiting on a human stage: the banner, the operator
// instructions recorded with the wait, and the selectable options, so the choice
// is visible without opening the stage view.
func waitingLines(r *protocol.RunDetail) []string {
if r.Status != protocol.RunStatusWaiting {
return nil
}
lines := []string{"⏸ Waiting for a person · stage " + r.CurrentStage}
if step, ok := lastWaitingStep(r); ok {
if prompt := strings.TrimSpace(protocol.WaitingPrompt(step.Output)); prompt != "" {
lines = append(lines, strings.Split(ansi.Strip(prompt), "\n")...)
}
if options := protocol.WaitingOptions(step.Output); len(options) > 0 {
lines = append(lines, "Options: "+strings.Join(options, ", "))
}
lines = append(lines, fmt.Sprintf("Decide: pipelines decide %d --option KEY [--feedback TEXT]", r.ID))
}
return lines
}
func completedWorkLines(r *protocol.RunDetail) []string {
var lines []string
for _, s := range r.Steps {
@@ -117,6 +145,9 @@ func completedWorkLines(r *protocol.RunDetail) []string {
}
func runOutputDocument(r *protocol.RunDetail, width int) []string {
if r.Status == protocol.RunStatusWaiting {
return waitingLines(r)
}
var notice []string
if r.Diagnostic != "" {
notice = append(notice, lipgloss.NewStyle().Foreground(themeError).Render("Stopped: "+ansi.Strip(r.Diagnostic)), "")
+122 -30
View File
@@ -101,6 +101,7 @@ func (m *Model) closeRuns() {
m.runGraphFocus = false
m.runGraphTop = 0
m.runGraphPan = 0
m.closeDecision()
}
func (m Model) visibleRuns() []protocol.RunSummary {
@@ -126,7 +127,7 @@ func (m Model) visibleRuns() []protocol.RunSummary {
}
labels := make([]string, len(runs))
for i, run := range runs {
labels[i] = fmt.Sprintf("#%d %s v%d %s %s %s %s", run.ID, run.Name, run.Version, run.Status, run.Outcome, run.CurrentStage, run.Diagnostic)
labels[i] = fmt.Sprintf("#%d %s v%d %s %s %s %s", run.ID, run.Label(), run.Version, run.Status, run.Outcome, run.CurrentStage, run.Diagnostic)
}
matched := make([]protocol.RunSummary, 0)
for _, match := range fuzzy.Find(query, labels) {
@@ -144,6 +145,48 @@ func (m *Model) selectRunStep(index int) {
}
}
// Run-detail section identity is defined once here and shared by rendering and
// the search/navigation helpers, so the titles, shortcut markers and section
// indices cannot drift apart.
type runSection struct {
Title string
Shortcut string
}
// runSectionNone is the "no section to focus" sentinel used by search navigation.
const runSectionNone = -1
// Run-detail section indices, in runSections order. Result and File changes
// default open; the rest default collapsed.
const (
runSectionProgress = iota
runSectionInput
runSectionResult
runSectionEvidence
runSectionDetails
runSectionFiles
runSectionCount
)
var runSections = []runSection{
{"Progress", "s"},
{"Task & input", "i"},
{"Result", "o"},
{"Evidence", "t"},
{"Execution details", "m"},
{"File changes", "d"},
}
// runSectionForShortcut maps a section shortcut key to its index.
func runSectionForShortcut(key string) (int, bool) {
for i, section := range runSections {
if section.Shortcut == key {
return i, true
}
}
return runSectionNone, false
}
func (m Model) runSectionKey(index int) string {
sequence := 0
if m.runDetail != nil && m.runStepIndex > 0 && m.runStepIndex <= len(m.runDetail.Steps) {
@@ -156,7 +199,7 @@ func (m Model) runSectionClosed(index int) bool {
if closed, ok := m.runCollapsed[m.runSectionKey(index)]; ok {
return closed
}
return index != 2 && index != 5
return index != runSectionResult && index != runSectionFiles
}
func (m *Model) toggleRunSection(index int) {
@@ -208,8 +251,8 @@ func (m Model) openOpenCodeEvidence() (tea.Model, tea.Cmd) {
if m.runCollapsed == nil {
m.runCollapsed = map[string]bool{}
}
for section := 0; section < 5; section++ {
m.runCollapsed[m.runSectionKey(section)] = section != 3
for section := 0; section < runSectionFiles; section++ {
m.runCollapsed[m.runSectionKey(section)] = section != runSectionEvidence
}
return m, nil
}
@@ -223,6 +266,8 @@ func runStatus(status string) string {
color = themeError
case "running", "queued":
color = themeAccent
case protocol.RunStatusWaiting:
color = themeAccent
}
return lipgloss.NewStyle().Foreground(color).Render(status)
}
@@ -242,6 +287,36 @@ func runDuration(start, end string) string {
return max(time.Duration(0), last.Sub(first)).Round(time.Second).String()
}
// stageVerdictLines renders a completed stage visit's derived verdict for the
// stage view: one line naming the chosen option and its concise reason, and a
// second naming the recorded artifacts the reason refers to. It returns nil for a
// nil verdict, so the view gains nothing rather than an empty heading, and it
// always states the option even when the reason is absent, so the derived choice
// is never hidden.
func stageVerdictLines(verdict *protocol.StageVerdict) []string {
if verdict == nil {
return nil
}
option := strings.TrimSpace(verdict.Option)
reason := strings.TrimSpace(verdict.Reason)
line := "Verdict:"
switch {
case option != "" && reason != "":
line += " " + option + " · " + reason
case option != "":
line += " " + option
case reason != "":
line += " " + reason
default:
return nil
}
lines := []string{line}
if len(verdict.Artifacts) > 0 {
lines = append(lines, "Referenced artifacts: "+strings.Join(verdict.Artifacts, ", "))
}
return lines
}
func valueLines(values map[string]any) []string {
if len(values) == 0 {
return []string{"No data yet."}
@@ -400,8 +475,10 @@ func (m Model) runSectionLines(width int) []string {
return nil
}
r := m.runDetail
titles := []string{"Progress", "Task & input", "Result", "Evidence", "Execution details", "File changes"}
shortcuts := []string{"s", "i", "o", "t", "m", "d"}
titles := make([]string, len(runSections))
for i, section := range runSections {
titles[i] = section.Title
}
summary := append(runResultLines(r), "", strings.Join(completedWorkLines(r), "\n"))
if m.runError != "" {
summary = append(summary, "Request error: "+m.runError)
@@ -411,36 +488,44 @@ func (m Model) runSectionLines(width int) []string {
editScope = strings.Join(r.WritePaths, ", ")
}
var output, input []string
if !m.runSectionClosed(2) {
if !m.runSectionClosed(runSectionResult) {
output = runOutputDocument(r, max(1, width-2))
}
if !m.runSectionClosed(1) {
if !m.runSectionClosed(runSectionInput) {
input = resultDocument(r.Input, max(1, width-2))
}
content := [][]string{summary, input, output, {"Choose a stage with n/p to inspect its retained evidence."}, {"Started: " + dateLabel(r.CreatedAt), "Finished: " + dateLabel(r.FinishedAt), "Duration: " + runDuration(r.CreatedAt, r.FinishedAt), "Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, "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))
content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Retry of run #%d", r.RetryOf))
}
content = append(content, []string{"Select a recorded stage visit with n/p to inspect its retained file diff."})
if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) {
step := r.Steps[m.runStepIndex-1]
titles[0] = "Stage progress"
titles[runSectionProgress] = "Stage progress"
summary = []string{m.progress(m.stepProgressStatus(step)) + " · " + runDuration(step.StartedAt, step.FinishedAt), "Route: " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target}
var stageOutput, stageInput, evidence []string
if !m.runSectionClosed(2) {
if !m.runSectionClosed(runSectionResult) {
stageOutput = resultDocument(step.Output, max(1, width-2))
}
if !m.runSectionClosed(1) {
if !m.runSectionClosed(runSectionInput) {
stageInput = resultDocument(step.Input, max(1, width-2))
}
if !m.runSectionClosed(3) {
if !m.runSectionClosed(runSectionEvidence) {
evidence = evidenceLines(step)
}
stageState := m.progress(m.stepProgressStatus(step))
if step.Outcome != "" && step.Target != "" {
stageState += " · " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target
}
stageOutput = append([]string{stageState, ""}, stageOutput...)
// The verdict leads the stage's result: it states the chosen option and its
// concise reason and names the recorded artifacts the reason refers to, so
// the derived choice is at the top of the stage view, complementing the
// state and output below it without adding a section.
head := []string{stageState, ""}
if verdict := stageVerdictLines(step.Verdict); len(verdict) > 0 {
head = append(head, verdict...)
}
stageOutput = append(head, stageOutput...)
if step.Status == "running" {
stageOutput = append([]string{m.loading("Working on " + step.Stage + " · result pending"), ""}, stageOutput...)
}
@@ -449,19 +534,19 @@ func (m Model) runSectionLines(width int) []string {
}
content = [][]string{summary, stageInput, stageOutput, evidence, {"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("Step: %d", step.Sequence)}}
if step.Control != nil {
content[4] = append(content[4], fmt.Sprintf("Runner visit: %d / %d", step.Control.Visit, step.Control.MaxVisits))
content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Runner visit: %d / %d", step.Control.Visit, step.Control.MaxVisits))
if step.Control.LimitReached {
content[4] = append(content[4], "Runtime limit stopped route: "+step.Control.ModelTarget)
content[runSectionDetails] = append(content[runSectionDetails], "Runtime limit stopped route: "+step.Control.ModelTarget)
}
for alias, read := range step.Control.Memory {
content[4] = append(content[4], fmt.Sprintf("Shared memory %s ← %s (visit sequence %d)", alias, read.Source, read.Sequence))
content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Shared memory %s ← %s (visit sequence %d)", alias, read.Source, read.Sequence))
}
}
if !m.runSectionClosed(2) {
content[2] = append(content[2], "", fileChangesSummary(step), artifactsSummary(step))
if !m.runSectionClosed(runSectionResult) {
content[runSectionResult] = append(content[runSectionResult], "", fileChangesSummary(step), artifactsSummary(step))
}
var diff []string
if !m.runSectionClosed(5) {
if !m.runSectionClosed(runSectionFiles) {
diff = append(stageDiffLines(step), artifactLines(step)...)
}
content = append(content, diff)
@@ -470,26 +555,26 @@ func (m Model) runSectionLines(width int) []string {
if receipt.Filename != "" {
line += " · " + receipt.Filename
}
content[4] = append(content[4], line)
content[runSectionDetails] = append(content[runSectionDetails], line)
if receipt.MessageID != "" {
content[4] = append(content[4], "Message ID: "+receipt.MessageID)
content[runSectionDetails] = append(content[runSectionDetails], "Message ID: "+receipt.MessageID)
}
if receipt.AttachmentURL != "" {
content[4] = append(content[4], "Attachment: "+receipt.AttachmentURL)
content[runSectionDetails] = append(content[runSectionDetails], "Attachment: "+receipt.AttachmentURL)
}
if receipt.Diagnostic != "" {
content[4] = append(content[4], "Notification diagnostic: "+receipt.Diagnostic)
content[runSectionDetails] = append(content[runSectionDetails], "Notification diagnostic: "+receipt.Diagnostic)
}
}
}
var lines []string
for _, i := range []int{2, 5, 0, 1, 3, 4} {
for _, i := range []int{runSectionResult, runSectionFiles, runSectionProgress, runSectionInput, runSectionEvidence, runSectionDetails} {
title := titles[i]
marker := "▾"
if m.runSectionClosed(i) {
marker = "▸"
}
lines = append(lines, bar(fmt.Sprintf("[%s] %s %s", shortcuts[i], marker, title), "", width, false))
lines = append(lines, bar(fmt.Sprintf("[%s] %s %s", runSections[i].Shortcut, marker, title), "", width, false))
if !m.runSectionClosed(i) {
for _, line := range content[i] {
for _, wrapped := range strings.Split(ansi.Wrap(line, max(1, width-2), ""), "\n") {
@@ -508,7 +593,7 @@ func (m Model) runSectionLines(width int) []string {
// The section containing the top visible detail row is the scroll focus.
func runFocusedSection(lines []string, top int) (int, string) {
row, title := 0, "Result"
row, title := 0, runSections[runSectionResult].Title
for i, line := range lines {
plain := ansi.Strip(line)
if i > top {
@@ -558,6 +643,9 @@ func (m Model) runActions() string {
if m.runDetail != nil {
text += " · a evidence"
}
if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting {
text += " · c decide"
}
if m.selectedFailedRun() > 0 {
text += " · r retry failed"
}
@@ -589,7 +677,7 @@ func (m Model) runsDetailsView(height int) string {
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))
text := fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Label(), 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), "…"))
}
@@ -612,7 +700,7 @@ func (m Model) runsDetailsView(height int) string {
return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, footer, true)
}
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)
header := bar(fmt.Sprintf("#%d %s · v%d", r.ID, r.Label(), r.Version), m.progress(r.Status)+" · "+runDuration(r.CreatedAt, r.FinishedAt), m.width, false)
if height <= 6 {
return fitBlock([]string{header, runHighlight(m.runSelectionLabel(), m.width), m.runActions() + " · Tab pane · Esc back"}, m.width, height)
}
@@ -636,7 +724,11 @@ func (m Model) runsDetailsView(height int) string {
lines := m.runSectionLines(m.runDetailWidth())
page := max(0, innerHeight-5)
top := max(0, min(m.runTop, max(0, len(lines)-page)))
footer := bar("o result · d diff · s progress · i input · t evidence · m details", fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)), max(1, m.width-4), false)
footerHint := "o result · d diff · s progress · i input · t evidence · m details"
if r.Status == protocol.RunStatusWaiting {
footerHint += " · c decide"
}
footer := bar(footerHint, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)), max(1, m.width-4), false)
label := m.runSelectionLabel()
if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) {
step := r.Steps[m.runStepIndex-1]
+3
View File
@@ -27,6 +27,9 @@ func (m Model) progress(status string) string {
color = themeError
case "canceled":
marker = "−"
case protocol.RunStatusWaiting:
marker = "⏸"
color = themeAccent
}
return lipgloss.NewStyle().Foreground(color).Render(marker + " " + status)
}
+8 -1
View File
@@ -147,7 +147,7 @@ func (m *Model) startSelectedRun() tea.Cmd {
m.runCollapsed = nil
m.runDetail = nil
m.runTop = 0
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace}
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Title: m.cliOptions.Title, Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace}
updated, cmd := m.runRequest(request)
*m = updated.(Model)
return cmd
@@ -282,6 +282,9 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.runGraphFocus {
switch msg.String() {
case "c":
if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting {
return m.openDecision()
}
m.runGraphTop, m.runGraphPan = m.runGraphFollow()
return m, nil
case "j", "down":
@@ -418,6 +421,10 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.runDetail != nil {
return m.runRequest(protocol.Message{Type: protocol.CancelRun, RunID: m.runDetail.ID})
}
case "c":
if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting {
return m.openDecision()
}
}
if m.runDetail != nil {
m.runTop = max(0, min(m.runTop, max(0, len(m.runSectionLines(m.runDetailWidth()))-m.runPageSize())))
+56 -4
View File
@@ -43,6 +43,24 @@ func TestRunFormAndInspection(t *testing.T) {
}
}
func TestRunTitleIsShownToOperator(t *testing.T) {
titled := protocol.RunSummary{ID: 1, Name: "bug fix", Version: 2, Title: "Fix the flaky login test", Status: "succeeded"}
if got := titled.Label(); got != "Fix the flaky login test" {
t.Fatalf("Label = %q, want the generated title", got)
}
if got := (protocol.RunSummary{Name: "bug fix"}).Label(); got != "bug fix" {
t.Fatalf("Label without a title = %q, want the pipeline name fallback", got)
}
m := New(context.Background(), "")
m.width = 100
m.height = 28
m.runOpen = true
m.runDetail = &protocol.RunDetail{RunSummary: titled}
if view := ansi.Strip(m.runsDetailsView(24)); !strings.Contains(view, "Fix the flaky login test") {
t.Fatalf("run detail header omitted the title:\n%s", view)
}
}
func runInspectionModel() Model {
m := New(context.Background(), "")
m.width = 100
@@ -84,7 +102,7 @@ func TestRunVisitSelectorSectionsAndScrolling(t *testing.T) {
t.Fatal("unselected or collapsed data leaked into details")
}
m = runKey(m, "i")
if m.runSectionClosed(1) {
if m.runSectionClosed(runSectionInput) {
t.Fatal("input section did not expand")
}
m = runKey(m, "pgdown")
@@ -101,11 +119,11 @@ func TestRunVisitSelectorSectionsAndScrolling(t *testing.T) {
t.Fatal("Home did not reach top")
}
m = runKey(m, "n")
if m.runStepIndex != 2 || !m.runSectionClosed(1) {
if m.runStepIndex != 2 || !m.runSectionClosed(runSectionInput) {
t.Fatal("attempt state not independent")
}
m = runKey(m, "p")
if m.runSectionClosed(1) {
if m.runSectionClosed(runSectionInput) {
t.Fatal("expansion not retained when revisiting attempt")
}
}
@@ -196,7 +214,7 @@ func TestRunSectionsOrderTitleAndNumberSelection(t *testing.T) {
if strings.Index(text, "Result") > strings.Index(text, "Task & input") {
t.Fatal("output must precede input")
}
if m.runSectionClosed(2) || !m.runSectionClosed(1) {
if m.runSectionClosed(runSectionResult) || !m.runSectionClosed(runSectionInput) {
t.Fatal("output should remain visible; input initially collapsed")
}
view := ansi.Strip(m.runsView(24))
@@ -226,3 +244,37 @@ func TestPipelineRunShortcutFiltersAndReturns(t *testing.T) {
t.Fatal("closing runs didn't return to pipeline")
}
}
// TestRunStepVerdictRenderedWhenPresent proves the rendered run detail states a
// completed visit's chosen option and its reason and names its referenced
// artifacts, that an absent reason still states the option, and that a step with a
// nil verdict shows no verdict line at all.
func TestRunStepVerdictRenderedWhenPresent(t *testing.T) {
m := runInspectionModel()
m.runDetail.Steps[0].Verdict = &protocol.StageVerdict{
Option: "success → verifier",
Reason: "Tests passed and the evidence is retained",
ReasonSource: protocol.VerdictReasonModel,
Artifacts: []string{"captures/shot.png", "report.txt"},
}
m.runStepIndex = 1
view := ansi.Strip(m.runsDetailsView(24))
for _, want := range []string{
"Verdict: success → verifier · Tests passed and the evidence is retained",
"Referenced artifacts: captures/shot.png, report.txt",
} {
if !strings.Contains(view, want) {
t.Fatalf("verdict detail missing %q:\n%s", want, view)
}
}
// An absent reason still states the chosen option rather than dropping it.
optionOnly := &protocol.StageVerdict{Option: "success → verifier", ReasonSource: protocol.VerdictReasonAbsent}
if got := ansi.Strip(strings.Join(stageVerdictLines(optionOnly), "\n")); got != "Verdict: success → verifier" {
t.Fatalf("option-only verdict = %q", got)
}
m.runDetail.Steps[0].Verdict = nil
view = ansi.Strip(m.runsDetailsView(24))
if strings.Contains(view, "Verdict:") || strings.Contains(view, "Referenced artifacts:") {
t.Fatalf("nil verdict must show no verdict line:\n%s", view)
}
}