b3c9575fde
- A stage refused for a Claude usage limit no longer fails its run: the runner tries the chats' Claude account auto-switch (per-home setting) and reruns the visit, else parks the run in the new waiting_quota status (persisted, with reset/resume time in run summaries, details and events) and resumes the same visit at reset + 1 min, also after a restart. resume_run / `pipelines resume` resumes now; cancel works on parked runs. The rerun visit gets a "# Previous attempt" interruption note. Subscription limits no longer say "top up the provider account". - run/retry into an account known to be limited are deferred (quota_policy defer/refuse/now; CLI refuses under --json/--yes unless --defer or --now). - failure_class on runs (quota, loop_exhausted, timeout, permission_denied, harness_error, blocked, environment, canceled, interrupted, budget, check_failed, other) in RunSummary/RunDetail/events, CLI inspect/runs/wait/ stats and the app failure line. - Claude permission denials (permission_denials / refused tool results) fail a blocked visit with permission_denied naming the tool use. - Harness failures are classified transient vs deterministic; deterministic ones (and a repeated empty readback) skip error self-loops; transient self-loops back off 15 s, 1 min, 4 min. - Whole-run USD budget: run --budget, server default (run-budget / get/set_run_settings); 80% warning notification, stop with class budget. - App: waiting_quota status/filter with resume time, Resume now and Cancel, failure class wording. Docs and skill references updated. Merges main (check stage, delivery gate, Claude stage restart survival, schedule changes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
3.4 KiB
Go
117 lines
3.4 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 {
|
|
OutputFormat string
|
|
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
|
|
// QuotaPolicy and BudgetUSD pass the CLI's --now/--defer and --budget.
|
|
QuotaPolicy string
|
|
BudgetUSD float64
|
|
}
|
|
|
|
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
|
|
}
|