Files
pipelines/internal/tui/cli_run.go
T
alan 0d7e81362f web: run pipelines from the browser and quiet background chat
Add the Run pipeline dialog with prompt, server directory and a per-run
notification choice; add --notify auto/on/off to run and retry; move the live
tool call onto the tool-count line and tick the reasoning duration; stop chat
frames from repainting a different screen.
2026-10-20 12:56:47 +01:00

113 lines
3.2 KiB
Go

package tui
import (
"context"
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
"github.com/sahilm/fuzzy"
"strings"
)
type RunOptions struct {
Pipeline, Prompt, Title, Workspace string
Yes, AllowTools bool
WritePaths []string
// Model and StageModels are the CLI's launch-time model overrides, passed
// through to the run request without adding a TUI picker (that is a follow-up).
Model string
StageModels map[string]string
NotifyMode string
}
func NewRun(ctx context.Context, url string, options RunOptions) Model {
m := New(ctx, url)
m.cliRun = true
m.cliOptions = options
m.runWorkspace = options.Workspace
m.runPicker = true
m.runPickerInput = newInput()
m.runPickerInput.Placeholder = "Search registered pipelines…"
m.runPickerInput.SetValue(options.Pipeline)
m.runPickerInput.Focus()
return m
}
func (m Model) runChoices() []protocol.PipelineSummary {
query := strings.TrimSpace(m.runPickerInput.Value())
if query == "" {
return m.pipelines
}
names := make([]string, len(m.pipelines))
for i, p := range m.pipelines {
names[i] = p.Name
}
var result []protocol.PipelineSummary
for _, match := range fuzzy.Find(query, names) {
result = append(result, m.pipelines[match.Index])
}
return result
}
func (m Model) updateRunPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
items := m.runChoices()
switch msg.String() {
case "esc":
return m, tea.Quit
case "down", "ctrl+n":
m.runPickerIndex = min(m.runPickerIndex+1, max(0, len(items)-1))
return m, nil
case "up", "ctrl+p":
m.runPickerIndex = max(0, m.runPickerIndex-1)
return m, nil
case "enter":
if len(items) > 0 {
m.runPicker = false
return m.requestPipeline(items[m.runPickerIndex].ID, items[m.runPickerIndex].Version)
}
return m, nil
}
var cmd tea.Cmd
m.runPickerInput, cmd = m.runPickerInput.Update(msg)
m.runPickerIndex = 0
return m, cmd
}
func (m Model) runPickerView(height int) string {
input := m.runPickerInput
input.Width = max(1, min(72, m.width-8))
lines := []string{"Run a pipeline in this repository", input.View(), "Repository: " + m.runWorkspace, "Enter select · ↑/↓ choose · Esc exit", ""}
items := m.runChoices()
start, end := selectionWindow(len(items), m.runPickerIndex, max(1, height-8))
if !m.loaded {
lines = append(lines, "Connecting to the pipeline service…")
} else if len(items) == 0 {
lines = append(lines, "No matching pipelines. Open pipelines and press b to create one from a template.")
}
for i := start; i < end; i++ {
prefix := " "
if i == m.runPickerIndex {
prefix = "▸ "
}
lines = append(lines, menuOption(fmt.Sprintf("%s%s · v%d · %d stages", prefix, items[i].Name, items[i].Version, items[i].Stages), i == m.runPickerIndex))
}
if m.detailError != "" {
lines = append(lines, m.detailError)
}
return popup(m.width, height, 100, lines)
}
func (m Model) configureCLIRun() (tea.Model, tea.Cmd) {
m.cliStarted = true
m.runPicker = false
updated, cmd := m.beginRun()
m = updated.(Model)
m.runPaths = append([]string(nil), m.cliOptions.WritePaths...)
if m.cliOptions.Prompt != "" {
m.runTask = m.cliOptions.Prompt
cmd = m.startSelectedRun()
return m, cmd
}
return m, cmd
}