fae1005962
Add `pipelines run --model PROVIDER/MODEL` and repeatable `--stage-model STAGE=PROVIDER/MODEL`, resolved with precedence per-stage > whole-run > the model pinned in the pipeline version. - A shared pure resolver (`pipeline.ParseModelOverride` / `pipeline.EffectiveModels`) owns the precedence and validation: every value must be a `provider/model` pair (`stage.ValidModel`), every stage key must exist in the pinned graph, an unknown key fails naming the valid keys, and a per-stage key that names a non-model stage is refused. - The server validates against the pinned version before admission (no run row is ever inserted for an invalid request), persists `model`/`stage_models` on the run and `provider`/`model` on each step, applies the effective pair to a clone of the stage definition so the stage and its repair/formatter path share it, overlays the returned run graph with the effective pair (presentation only), and reuses the recorded overrides on retry. - The run record echoes the overrides it was launched with and each step records the provider/model it actually ran with; the TUI Evidence pane renders that effective pair. The pinned pipeline version and `show --version N` are never modified. - CLI help, `docs/cli.md` and the packaged authoring skill references document the flags and the precedence. A TUI override picker remains a documented follow-up; the CLI is the deliverable. Tests: pure precedence/validation table tests, store round-trip and request-key-mismatch plus migration, server admission/application/overlay/retry with a controlled executor, CLI flag/help/malformed-value tests, and a TUI evidence test.
112 lines
3.2 KiB
Go
112 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
|
|
}
|
|
|
|
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
|
|
}
|