Files
pipelines/internal/cli/model_picker.go
T
alan 05ae530442 Make Pipelines Docker-only with OpenCode and Pi
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers.

Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent.

Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
2026-10-11 23:00:25 +01:00

61 lines
1.7 KiB
Go

package cli
import (
"context"
"encoding/json"
"flag"
"fmt"
"git.a-wan.net/alan/pipelines/internal/harness"
"os"
)
// choose-model is used by the installer without piping over its interactive input.
func (a App) chooseModel(ctx context.Context, args []string) error {
f := flag.NewFlagSet("choose-model", flag.ContinueOnError)
f.SetOutput(a.Err)
options := f.String("options-file", "", "JSON array of available exact model IDs")
output := f.String("output", "", "Private new file for the chosen model")
title := f.String("title", "Choose model", "Picker title")
purpose := f.String("purpose", "", "Explanation of this model's purpose")
step := f.String("step", "", "Step label such as 'Step 1 of 2'")
current := f.String("current", "", "Saved model to preselect")
if err := f.Parse(args); err != nil {
return err
}
if *options == "" || *output == "" || len(f.Args()) > 0 {
return fmt.Errorf("choose-model requires --options-file and --output")
}
data, err := os.ReadFile(*options)
if err != nil {
return err
}
var models []string
if len(data) > 1<<20 || json.Unmarshal(data, &models) != nil {
return fmt.Errorf("invalid model catalog")
}
for _, m := range models {
if !harness.ValidModel(m) {
return fmt.Errorf("invalid model ID %q", m)
}
}
selected, err := harness.Pick(ctx, harness.Selection{
Title: *title,
Purpose: *purpose,
Step: *step,
Options: models,
Current: *current,
}, a.In, a.Out)
if err != nil {
return err
}
file, err := os.OpenFile(*output, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
return err
}
if _, err = file.WriteString(selected + "\n"); err != nil {
file.Close()
return err
}
return file.Close()
}