From 42600f6961dbae2e95f9df207715321c7c4d23bf Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 9 Oct 2026 14:13:09 +0100 Subject: [PATCH] Open a run's pinned pipeline from the runs page --- README.md | 2 + docs/cli.md | 3 + internal/tui/dashboard.go | 8 ++- internal/tui/model.go | 2 +- internal/tui/run_detail.go | 39 ++++++++++- internal/tui/run_pipeline_test.go | 108 ++++++++++++++++++++++++++++++ internal/tui/runs.go | 2 + 7 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 internal/tui/run_pipeline_test.go diff --git a/README.md b/README.md index 6c1c3300..5a87d867 100644 --- a/README.md +++ b/README.md @@ -123,4 +123,6 @@ In the TUI, press **d** (or use **:drafts**) to browse retained drafts, includin CLI-created ones. **e** reopens a draft, **v** validates it, and **s** opens explicit submission confirmation. Drafts remain retained after submission. +From a run, press **p** / **:pipeline** to open the pipeline version it used. + More: [CLI](docs/cli.md) · [installation](docs/install.md) · [pipeline format](internal/author/skill/references/format.md). diff --git a/docs/cli.md b/docs/cli.md index e967fc26..0c9040f4 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -100,6 +100,9 @@ transient client logs are presentation, not separate server capabilities. ## Scripted runs +On either the runs list or run inspector, press `p` (or use `:pipeline`) to open +the selected run's exact pipeline version. Navigation does not cancel the run. + ```sh cd ~/repos/project pipelines run "bug fix" "Fix the layout" --json diff --git a/internal/tui/dashboard.go b/internal/tui/dashboard.go index 29ece9c7..8a6a2166 100644 --- a/internal/tui/dashboard.go +++ b/internal/tui/dashboard.go @@ -13,7 +13,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/protocol" ) -var commands = []string{":logs", ":new", ":drafts", ":templates", ":refresh", ":ping", ":edit", ":submit", ":versions", ":run", ":runs", ":home", ":quit"} +var commands = []string{":logs", ":new", ":drafts", ":templates", ":refresh", ":ping", ":edit", ":submit", ":versions", ":run", ":runs", ":pipeline", ":home", ":quit"} func (m Model) footerContent() string { label := fmt.Sprintf(" LOGS %d · :logs ", len(m.lines)) @@ -82,6 +82,10 @@ func (m Model) pageCommands() []string { detailPage := m.keys.detail && !m.runOpen for _, command := range commands { switch command { + case ":pipeline": + if id, version := m.selectedRunPipeline(); id <= 0 || version <= 0 { + continue + } case ":new", ":ping", ":templates": if !m.homePage() { continue @@ -141,6 +145,8 @@ func (m Model) updatePalette(msg tea.KeyMsg) (tea.Model, tea.Cmd) { m.paletteOpen = false m.keys.palette = false switch command { + case ":pipeline": + return m.openRunPipeline() case ":drafts": return m.openDrafts() case ":templates": diff --git a/internal/tui/model.go b/internal/tui/model.go index ff70f2ed..cbd21702 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -75,7 +75,7 @@ func (k keyMap) ShortHelp() []key.Binding { return []key.Binding{key.NewBinding(key.WithKeys("n", "p"), key.WithHelp("n/p", "template")), key.NewBinding(key.WithKeys("v"), key.WithHelp("v", "render/source")), key.NewBinding(key.WithKeys("enter"), key.WithHelp("Enter", "use template")), k.cancel} } if k.runs { - return []key.Binding{k.commands, key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "select/scroll")), key.NewBinding(key.WithKeys("pgup", "pgdown"), key.WithHelp("PgUp/Dn", "page")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("Esc", "back"))} + return []key.Binding{k.commands, key.NewBinding(key.WithKeys("p"), key.WithHelp("p", "pipeline")), key.NewBinding(key.WithKeys("tab"), key.WithHelp("Tab", "pane")), key.NewBinding(key.WithKeys("j", "k"), key.WithHelp("j/k", "select/scroll")), key.NewBinding(key.WithKeys("pgup", "pgdown"), key.WithHelp("PgUp/Dn", "page")), key.NewBinding(key.WithKeys("esc"), key.WithHelp("Esc", "back"))} } 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"))} diff --git a/internal/tui/run_detail.go b/internal/tui/run_detail.go index 49139ceb..c00f7b2a 100644 --- a/internal/tui/run_detail.go +++ b/internal/tui/run_detail.go @@ -9,10 +9,43 @@ import ( "time" "git.a-wan.net/alan/pipelines/internal/protocol" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/ansi" ) +func (m Model) selectedRunPipeline() (int64, int) { + if !m.runOpen { + return 0, 0 + } + if m.runDetail != nil { + return m.runDetail.PipelineID, m.runDetail.Version + } + if m.requestedRunID > 0 || m.runStartRequest != "" { + return 0, 0 + } + runs := m.visibleRuns() + if len(runs) == 0 { + return 0, 0 + } + r := runs[min(m.runIndex, len(runs)-1)] + return r.PipelineID, r.Version +} + +func (m Model) openRunPipeline() (tea.Model, tea.Cmd) { + id, version := m.selectedRunPipeline() + if id <= 0 || version <= 0 { + m.runError = "Select a loaded run to open its pipeline." + return m, nil + } + m.closeRuns() + // Explicit navigation must not trigger the CLI's initial auto-run flow. + if m.cliRun { + m.cliStarted = true + } + return m.requestPipeline(id, version) +} + func (m *Model) closeRuns() { m.runOpen = false m.keys.runs = false @@ -320,12 +353,12 @@ func (m Model) runsView(height int) string { if m.runError != "" { rows = append(rows, m.runError) } - return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, "j/k select · Enter inspect", true) + return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, "j/k select · Enter inspect · p pipeline", 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) if height <= 6 { - return fitBlock([]string{header, m.runSelectionLabel(), "Tab pane · Esc back"}, m.width, height) + return fitBlock([]string{header, m.runSelectionLabel(), "p pipeline · Tab pane · Esc back"}, m.width, height) } innerHeight := height - 2 sidebar := m.runSidebarWidth() @@ -365,7 +398,7 @@ func (m Model) runsView(height int) string { lines := m.runSectionLines(max(1, rightWidth-4)) page := max(0, innerHeight-4) top := max(0, min(m.runTop, max(0, len(lines)-page))) - footer := fmt.Sprintf("%d–%d / %d · s/i/o/t/m sections · PgUp/Dn · Esc back", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)) + footer := fmt.Sprintf("%d–%d / %d · s/i/o/t/m sections · p pipeline · PgUp/Dn · Esc back", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)) label := m.runSelectionLabel() if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) { label = fmt.Sprintf("Details · %s · step %d", r.Steps[m.runStepIndex-1].Stage, r.Steps[m.runStepIndex-1].Sequence) diff --git a/internal/tui/run_pipeline_test.go b/internal/tui/run_pipeline_test.go new file mode 100644 index 00000000..72180410 --- /dev/null +++ b/internal/tui/run_pipeline_test.go @@ -0,0 +1,108 @@ +package tui + +import ( + "context" + "net/http/httptest" + "path/filepath" + "slices" + "strings" + "testing" + "time" + + "git.a-wan.net/alan/pipelines/internal/pipeline" + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/server" + tea "github.com/charmbracelet/bubbletea" +) + +func TestRunPageOpensPinnedPipelineWithoutCancellingRun(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "runs.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "workflow", pipeline.Template([]string{"original"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + id := items[0].ID + if _, err := store.Submit(ctx, "workflow", pipeline.Template([]string{"updated"}, true)); err != nil { + t.Fatal(err) + } + srv := httptest.NewServer(server.Handler(ctx, store)) + defer srv.Close() + m := New(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect") + connected := m.connect()().(connectedMsg) + defer connected.conn.CloseNow() + updated, read := m.Update(connected) + m = updated.(Model) + updated, read = m.Update(read()) + m = updated.(Model) + d, err := store.Get(ctx, id, 1) + if err != nil { + t.Fatal(err) + } + runID, _, err := store.CreateRun(ctx, d, "navigation", "/repo", false, nil, map[string]any{"prompt": "task"}) + if err != nil { + t.Fatal(err) + } + run, err := store.GetRun(ctx, runID) + if err != nil { + t.Fatal(err) + } + m.runOpen = true + m.keys.runs = true + m.runDetail = run + m.requestedRunID = runID + m.cliRun = true + m.cliStarted = false + if !slices.Contains(m.pageCommands(), ":pipeline") { + t.Fatal("run page is missing pipeline command") + } + updated, send := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'p'}}) + m = updated.(Model) + if send == nil || m.runOpen || !m.detailLoading || m.requestedPipelineID != id || m.requestedVersion != 1 || !m.cliStarted { + t.Fatal("incorrect run-to-pipeline navigation") + } + if _, ok := send().(sentMsg); !ok { + t.Fatal("pipeline request failed") + } + updated, _ = m.Update(read()) + m = updated.(Model) + if m.detail == nil || m.detail.Version != 1 || m.detail.LatestVersion != 2 || m.detail.Graph.Stages[0].Key != "original" || m.runForm != 0 { + t.Fatal("navigation did not open the run's exact immutable version", m.detail) + } + after, err := store.GetRun(ctx, runID) + if err != nil || after.Status != run.Status { + t.Fatal("navigation changed run state", after, err) + } + updated, _ = m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run})) + m = updated.(Model) + if m.runOpen || m.runDetail != nil || m.detail.Version != 1 { + t.Fatal("late polling response reopened the run page") + } +} + +func TestRunsListPipelineCommandUsesSelectedFilteredRun(t *testing.T) { + m := New(context.Background(), "") + m.runOpen = true + m.keys.runs = true + m.runPipelineID = 42 + m.runs = []protocol.RunSummary{{ID: 1, PipelineID: 1, Version: 9}, {ID: 2, PipelineID: 42, Version: 3}, {ID: 3, PipelineID: 42, Version: 4}} + m.runIndex = 1 + if id, version := m.selectedRunPipeline(); id != 42 || version != 4 { + t.Fatal("wrong selected run", id, version) + } + m.commandInput = newInput() + m.commandInput.SetValue(":pipeline") + updated, _ := m.updatePalette(tea.KeyMsg{Type: tea.KeyEnter}) + m = updated.(Model) + if m.runOpen || m.requestedPipelineID != 42 || m.requestedVersion != 4 { + t.Fatal("palette did not open selected pipeline") + } + if slices.Contains(m.pageCommands(), ":pipeline") { + t.Fatal("run-only command leaked onto pipeline page") + } +} diff --git a/internal/tui/runs.go b/internal/tui/runs.go index c352797c..683a4920 100644 --- a/internal/tui/runs.go +++ b/internal/tui/runs.go @@ -156,6 +156,8 @@ func (m Model) runFormView(height int) string { func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) { runs := m.visibleRuns() switch msg.String() { + case "p": + return m.openRunPipeline() case "esc": if m.runDetail != nil || m.requestedRunID > 0 || m.runStartRequest != "" { m.runDetail = nil