f3e0593f4d
Add a bounded, never-empty title to every run. `pipelines run --title "..."` sets it explicitly and skips model generation; otherwise the server generates it from the prompt through the shared summariser and falls back to the prompt's first line, recording title_source (model/fallback/explicit) and title_model. - protocol/store: RunSummary.Title plus Label(), a set_run_title message, title columns with an idempotent migration, CreateRunTitled, and SetRunTitle renames. - summarise: Title/GenerateTitle/DeriveTitle/ExplicitTitle bounded to TitleCap. - runner: generate the title outside the admission lock and only for a request that starts a run; a replay reuses the stored title and an explicit title skips the model entirely. - CLI: `--title` on run and a `title <run-id> "<title>"` rename command; human `runs` and `inspect` show the title beside the pipeline name and version. - TUI: the run list row, run detail header, Home run cards and last-run line, and the pipeline Results line show the title via Label(). Tests cover storage/migration/fallback, explicit-title and rename, the end-to-end CLI flow, and title rendering; CLI and operations docs updated.
108 lines
3.0 KiB
Go
108 lines
3.0 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
|
|
}
|
|
|
|
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
|
|
}
|