Files
pipelines/cmd/pipelines/main.go
T
alan 108c29f9eb One harness setup path: pipelines harness setup <claude|codex|opencode|pi>
Checks the CLI on the server's PATH (install command when missing), signs in
with the harness's own login only when needed (--login forces it), keeps the
OpenCode/Pi model pickers, and verifies with the server's check. Works on
native and Docker installs (Docker delegates to the container setup); --host
is a hidden compatibility alias. harness list shows all four harnesses'
installed/signed-in/configured/default status. ./install --opencode|--pi now
point to the command; ./install ends with the next-step hint.
2026-11-02 16:11:04 +00:00

102 lines
2.8 KiB
Go

package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"git.a-wan.net/alan/pipelines/internal/author"
"git.a-wan.net/alan/pipelines/internal/cli"
"git.a-wan.net/alan/pipelines/internal/installation"
"os"
"os/signal"
"path/filepath"
"syscall"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
app := cli.App{Out: os.Stdout, Err: os.Stderr, In: os.Stdin}
args := os.Args[1:]
executable, err := os.Executable()
if len(args) > 0 && args[0] == "skill" {
if len(args) == 2 && args[1] == "install" {
var dirs []string
dirs, err = author.InstallAllSkills()
if err == nil {
_, err = author.InstallManagerSkill()
}
if err == nil {
for _, dir := range dirs {
fmt.Println("Installed skill:", dir)
}
return
}
} else {
err = fmt.Errorf("usage: pipelines skill install")
}
}
if err == nil && len(args) > 0 && args[0] == "service" {
err = installation.ServiceCommand(ctx, executable, args[1:], os.Stdout, os.Stderr)
if err == nil {
return
}
}
var config *installation.Config
if err == nil {
config, err = installation.Load(executable)
}
if err == nil && config != nil {
err = config.Environment()
if err == nil && len(args) > 0 && installation.Service(args[0]) {
err = syscall.Exec(config.Python, append([]string{config.Python, filepath.Join(config.Prefix, "lib/manage.py"), "--prefix", config.Prefix}, args...), os.Environ())
}
if len(args) == 0 {
args = []string{"tui"}
}
}
if err == nil && config == nil && len(args) > 0 && args[0] == "uninstall" {
err = installation.Uninstall(executable, args[1:], os.Stdin, os.Stdout)
if err == nil {
return
}
}
if err == nil && config == nil && len(args) > 0 && args[0] == "serve" {
var server string
server, err = installation.ServerExecutable(executable)
if err == nil {
err = syscall.Exec(server, append([]string{server}, args[1:]...), os.Environ())
}
}
if err == nil && len(args) > 0 && installation.Service(args[0]) {
err = fmt.Errorf("%s is a legacy managed-service command; use pipelines serve, or select an existing installation with PIPELINES_PREFIX", args[0])
}
if err == nil && len(args) == 0 {
args = []string{"tui"}
}
if err == nil {
app.Install = config
err = app.Run(ctx, args)
}
if err != nil {
var dispatched *cli.ExitError
if errors.As(err, &dispatched) {
// A dispatched subprocess already streamed its own output.
os.Exit(dispatched.ExitCode())
}
jsonMode := false
for _, arg := range os.Args[1:] {
if arg == "--json" || arg == "-json" || arg == "--json=true" {
jsonMode = true
}
}
if jsonMode {
_ = json.NewEncoder(os.Stderr).Encode(map[string]string{"type": "error", "error": err.Error()})
} else {
fmt.Fprintln(os.Stderr, "pipelines:", err)
}
os.Exit(1)
}
}