76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/client"
|
|
"git.a-wan.net/alan/pipelines/internal/tui"
|
|
)
|
|
|
|
func main() {
|
|
url := flag.String("url", "ws://127.0.0.1:8080/connect", "server WebSocket URL")
|
|
run := flag.Bool("run", false, "Select a registered pipeline and run it in this repository")
|
|
name := flag.String("pipeline", "", "Registered pipeline name; omitted opens fuzzy selection")
|
|
prompt := flag.String("prompt", "", "Task prompt; omitted opens a multiline composer")
|
|
workspace := flag.String("workspace", "", "Repository directory (defaults to current directory with -run)")
|
|
yes := flag.Bool("yes", false, "Compatibility flag; TUI actions still require a confirmation modal")
|
|
allow := flag.Bool("allow-tools", false, "Compatibility flag; tools follow the pipeline stages")
|
|
paths := flag.String("write-paths", "", "Optional narrower edit scope; default is the run directory")
|
|
flag.Parse()
|
|
explicit := false
|
|
flag.Visit(func(value *flag.Flag) {
|
|
if value.Name == "url" {
|
|
explicit = true
|
|
}
|
|
})
|
|
if !explicit {
|
|
if value := os.Getenv("PIPELINES_URL"); value != "" {
|
|
*url = value
|
|
} else {
|
|
configured, err := client.ConfiguredURL()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
if configured != "" {
|
|
*url = configured
|
|
}
|
|
}
|
|
}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
model := tui.New(ctx, *url)
|
|
if *run {
|
|
if *workspace == "" {
|
|
var err error
|
|
*workspace, err = os.Getwd()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
options := tui.RunOptions{Pipeline: *name, Prompt: *prompt, Workspace: *workspace, Yes: *yes, AllowTools: *allow}
|
|
for _, path := range strings.Split(*paths, ",") {
|
|
if path = strings.TrimSpace(path); path != "" {
|
|
options.WritePaths = append(options.WritePaths, path)
|
|
}
|
|
}
|
|
if *yes && (*name == "" || strings.TrimSpace(*prompt) == "") {
|
|
fmt.Fprintln(os.Stderr, "-yes requires -pipeline and a nonempty -prompt")
|
|
os.Exit(2)
|
|
}
|
|
model = tui.NewRun(ctx, *url, options)
|
|
}
|
|
if _, err := tea.NewProgram(model, tea.WithAltScreen()).Run(); err != nil {
|
|
cancel()
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|