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.
This commit is contained in:
+159
-26
@@ -8,14 +8,17 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/author"
|
||||
"git.a-wan.net/alan/pipelines/internal/buildinfo"
|
||||
"git.a-wan.net/alan/pipelines/internal/client"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/harness"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/runinspect"
|
||||
@@ -30,13 +33,14 @@ type App struct {
|
||||
In io.Reader
|
||||
}
|
||||
type options struct {
|
||||
harness string
|
||||
url, name, prompt, template, workspace, paths, key, opencode, model string
|
||||
output string
|
||||
conflict string
|
||||
all bool
|
||||
json, source, noOpen, yes, allow, createOnly, force, wait bool
|
||||
version, expected int
|
||||
timeout time.Duration
|
||||
timeout, waitTimeout time.Duration
|
||||
}
|
||||
|
||||
func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
@@ -48,13 +52,15 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.DurationVar(&o.timeout, "timeout", 30*time.Second, "Timeout per server request")
|
||||
switch command {
|
||||
case "provider-check":
|
||||
f.StringVar(&o.harness, "harness", "opencode", "Provider-check harness: opencode or configured pi")
|
||||
f.StringVar(&o.model, "model", envOr("PIPELINES_DEFAULT_MODEL", ""), "Provider/model to validate with one tool-free generation")
|
||||
f.BoolVar(&o.yes, "yes", false, "Approve the small validation generation without prompting")
|
||||
case "new", "edit":
|
||||
f.StringVar(&o.harness, "harness", "", "Authoring harness: configured opencode/pi, or nvim")
|
||||
f.BoolVar(&o.yes, "yes", false, "Approve draft creation/editor launch without prompting")
|
||||
f.StringVar(&o.name, "name", "", "Pipeline name (or edit ID)")
|
||||
f.StringVar(&o.prompt, "prompt", "", "Request to give OpenCode; omitted asks what to change")
|
||||
f.BoolVar(&o.noOpen, "no-open", false, "Create the draft without opening OpenCode")
|
||||
f.StringVar(&o.prompt, "prompt", "", "Request to give the configured harness; omitted asks what to change")
|
||||
f.BoolVar(&o.noOpen, "no-open", false, "Create the draft without opening the configured harness")
|
||||
f.StringVar(&o.opencode, "opencode", envOr("PIPELINES_OPENCODE", "opencode"), "Host OpenCode executable")
|
||||
if command == "new" {
|
||||
f.StringVar(&o.template, "template", "", "Optional template key; omitted starts a one-stage draft")
|
||||
@@ -90,18 +96,21 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
|
||||
f.IntVar(&o.version, "version", 0, "Version to run (default: latest)")
|
||||
f.BoolVar(&o.wait, "wait", false, "In JSON mode, wait for a terminal run state")
|
||||
f.DurationVar(&o.waitTimeout, "wait-timeout", 0, "Client limit for --wait after the run is admitted (0 waits until terminal); separate from per-request --timeout")
|
||||
case "runs":
|
||||
f.StringVar(&o.name, "pipeline", "", "Filter by exact pipeline name or ID")
|
||||
case "retry":
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm retry without an interactive prompt")
|
||||
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
|
||||
f.BoolVar(&o.wait, "wait", false, "Wait for the new run to finish")
|
||||
f.DurationVar(&o.waitTimeout, "wait-timeout", 0, "Client limit for --wait (0 waits until the run ends); independent of --timeout")
|
||||
case "cancel", "draft-delete":
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
|
||||
case "debug":
|
||||
f.StringVar(&o.harness, "harness", "", "Debugging harness: configured opencode/pi, or nvim")
|
||||
f.BoolVar(&o.yes, "yes", false, "Approve opening a debugging session without prompting")
|
||||
f.StringVar(&o.opencode, "opencode", envOr("PIPELINES_OPENCODE", "opencode"), "Host OpenCode executable")
|
||||
f.BoolVar(&o.noOpen, "no-open", false, "Print the investigation prompt without launching OpenCode")
|
||||
f.BoolVar(&o.noOpen, "no-open", false, "Print the investigation prompt without launching the configured harness")
|
||||
}
|
||||
f.Usage = func() {
|
||||
fmt.Fprintf(a.Out, "Usage: pipelines %s\n", usage[command])
|
||||
@@ -167,6 +176,15 @@ func parse(f *flag.FlagSet, args []string) error {
|
||||
}
|
||||
|
||||
func (a App) Run(ctx context.Context, args []string) error {
|
||||
if len(args) > 0 && args[0] == "choose-model" {
|
||||
return a.chooseModel(ctx, args[1:])
|
||||
}
|
||||
if len(args) > 0 && args[0] == "harness" {
|
||||
return a.harness(ctx, args[1:])
|
||||
}
|
||||
if len(args) > 0 && args[0] == "--version" {
|
||||
args = append([]string{"version"}, args[1:]...)
|
||||
}
|
||||
// Global selectors may appear before the command as well as after it.
|
||||
leading := 0
|
||||
for leading < len(args) {
|
||||
@@ -186,6 +204,11 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if leading == len(args) {
|
||||
return fmt.Errorf("a command is required; use pipelines help")
|
||||
}
|
||||
// Harness preferences are local, even when an agent's standard CLI
|
||||
// prefix includes a server URL. No server mutation occurs here.
|
||||
if args[leading] == "harness" {
|
||||
return a.harness(ctx, args[leading+1:])
|
||||
}
|
||||
args = append(append([]string{}, args[leading:]...), args[:leading]...)
|
||||
}
|
||||
if len(args) == 0 || args[0] == "help" || args[0] == "--help" || args[0] == "-h" {
|
||||
@@ -215,10 +238,21 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
if o.timeout <= 0 || o.version < 0 || o.expected < 0 {
|
||||
return fmt.Errorf("timeout must be positive and versions nonnegative")
|
||||
if o.timeout <= 0 || o.waitTimeout < 0 || o.version < 0 || o.expected < 0 {
|
||||
return fmt.Errorf("timeout must be positive, wait-timeout nonnegative, and versions nonnegative")
|
||||
}
|
||||
pos := f.Args()
|
||||
if command == "version" {
|
||||
if len(pos) != 0 {
|
||||
return fmt.Errorf("version takes no arguments")
|
||||
}
|
||||
build := buildinfo.Current()
|
||||
if o.json {
|
||||
return a.output(build)
|
||||
}
|
||||
fmt.Fprintf(a.Out, "pipelines %s (commit %s)\n", build.Version, build.Commit)
|
||||
return nil
|
||||
}
|
||||
if command == "provider-check" {
|
||||
if len(pos) != 0 {
|
||||
return fmt.Errorf("provider-check takes no positional arguments")
|
||||
@@ -230,12 +264,38 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if err := a.confirmAction("Validate "+o.model+" with one small tool-free generation (provider charges may apply)?", o.yes); err != nil {
|
||||
return err
|
||||
}
|
||||
config, err := harness.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A Docker-linked profile validates through its existing Compose service
|
||||
// with the original cwd/model/timeout and -T for machine mode. Container
|
||||
// profiles have no DockerDirectory, so the inner check cannot recurse.
|
||||
if profile, ok := config.Profiles[o.harness]; ok && profile.DockerDirectory != "" {
|
||||
return a.providerCheckDocker(ctx, o, profile)
|
||||
}
|
||||
check, cancel := context.WithTimeout(ctx, o.timeout)
|
||||
defer cancel()
|
||||
operations := &stage.OperationLog{}
|
||||
session := ""
|
||||
c := stage.OpenCodeClient{Operations: operations, OnGenerationSession: func(id, backend, reference string, active bool) error { session = id; return nil }}
|
||||
text, err := c.Generate(check, stage.ModelConfig{Provider: provider, Model: model}, "Provider connection validation only. Do not use tools. Reply with exactly PIPELINES_PROVIDER_OK.")
|
||||
var generator stage.ModelGenerator
|
||||
switch o.harness {
|
||||
case "opencode":
|
||||
generator = &stage.OpenCodeClient{Operations: operations, OnGenerationSession: func(id, backend, reference string, active bool) error { session = id; return nil }}
|
||||
case "pi":
|
||||
profile, ok := config.Profiles["pi"]
|
||||
if !ok {
|
||||
return fmt.Errorf("Pi is not configured on this computer")
|
||||
}
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
generator = &stage.PiClient{Executable: profile.Executable, Directory: cwd, Tools: []string{}, OnOwnership: func(id, reference string, active bool) error { session = id; return nil }}
|
||||
default:
|
||||
return fmt.Errorf("provider-check harness must be opencode or pi")
|
||||
}
|
||||
text, err := generator.Generate(check, stage.ModelConfig{Harness: o.harness, Provider: provider, Model: model}, "Provider connection validation only. Do not use tools. Reply with exactly PIPELINES_PROVIDER_OK.")
|
||||
if err == nil && strings.TrimSpace(text) != "PIPELINES_PROVIDER_OK" {
|
||||
err = fmt.Errorf("model returned a response but did not complete the validation instruction")
|
||||
}
|
||||
@@ -422,7 +482,18 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
debug := runinspect.New(response.RunDetail, executable, o.url)
|
||||
// nvim is a client-side editor: keep the native host prefix. A configured
|
||||
// harness (including a Docker-linked one) gets the shared Docker-aware prefix.
|
||||
var prefix string
|
||||
if o.harness == "nvim" {
|
||||
prefix, err = harness.CLIPrefix(harness.Profile{}, o.url, executable)
|
||||
} else {
|
||||
prefix, err = harness.CLIPrefixFor(o.harness, o.url, executable)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
debug := runinspect.New(response.RunDetail, prefix)
|
||||
definition, definitionErr := call(protocol.Message{Type: protocol.GetPipeline, PipelineID: response.RunDetail.PipelineID, Version: response.RunDetail.Version})
|
||||
if definitionErr != nil {
|
||||
debug.Prompt += "\nPinned pipeline definition unavailable: " + definitionErr.Error() + "\n"
|
||||
@@ -435,7 +506,7 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
debug.Prompt += "\nServer-side live session evidence unavailable: " + evidenceErr.Error() + "\n"
|
||||
} else {
|
||||
data, _ := json.Marshal(live.Evidence)
|
||||
debug.Prompt += "\nRead-only retained OpenCode evidence retrieved on the execution computer:\n" + string(data) + "\n"
|
||||
debug.Prompt += "\nRead-only, bounded and credential-redacted OpenCode session evidence for the latest session-bearing steps, retrieved on the execution computer:\n" + string(data) + "\n"
|
||||
}
|
||||
if o.json {
|
||||
return a.output(debug)
|
||||
@@ -454,7 +525,19 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if debug.ContextFile != "" {
|
||||
fmt.Fprintln(a.Out, "Retained debugging context:", debug.ContextFile)
|
||||
}
|
||||
cmd := debug.Command(ctx, o.opencode)
|
||||
var cmd *exec.Cmd
|
||||
if o.harness == "nvim" {
|
||||
debug, err = debug.PrepareFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd = exec.CommandContext(ctx, "nvim", "-R", debug.ContextFile)
|
||||
} else {
|
||||
cmd, err = harness.Command(ctx, o.harness, debug.Workspace, debug.Prompt, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cmd.Stdin = a.In
|
||||
cmd.Stdout = a.Out
|
||||
cmd.Stderr = a.Err
|
||||
@@ -564,6 +647,11 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
case "ping":
|
||||
fmt.Fprintln(a.Out, "Connected ·", r.Time)
|
||||
if r.Build != nil {
|
||||
fmt.Fprintf(a.Out, "Server: %s (commit %s)\n", r.Build.Version, r.Build.Commit)
|
||||
} else {
|
||||
fmt.Fprintln(a.Out, "Server build: unavailable (older server)")
|
||||
}
|
||||
case "connection":
|
||||
fmt.Fprintln(a.Out, "Server:", o.url)
|
||||
for _, n := range r.NotificationEndpoints {
|
||||
@@ -784,7 +872,7 @@ func (a App) author(ctx context.Context, command string, pos []string, o *option
|
||||
return fmt.Errorf("pipeline already exists; use edit or choose another name")
|
||||
}
|
||||
}
|
||||
source = pipeline.WithDefaultModel(pipeline.Template([]string{"worker"}, true), r.DefaultModel)
|
||||
source = pipeline.WithDefaults(pipeline.Template([]string{"worker"}, true), r.DefaultModel, r.DefaultHarness)
|
||||
if o.template != "" {
|
||||
r, err := call(protocol.Message{Type: protocol.ListTemplates})
|
||||
if err != nil {
|
||||
@@ -805,7 +893,7 @@ func (a App) author(ctx context.Context, command string, pos []string, o *option
|
||||
}
|
||||
confirmation := "Create a retained draft?"
|
||||
if !o.noOpen && !o.json {
|
||||
confirmation = "Create a retained draft and open OpenCode?"
|
||||
confirmation = "Create a retained draft and open the configured harness?"
|
||||
}
|
||||
if err := a.confirmAction(confirmation, o.yes); err != nil {
|
||||
return err
|
||||
@@ -822,14 +910,22 @@ func (a App) author(ctx context.Context, command string, pos []string, o *option
|
||||
return nil
|
||||
}
|
||||
// Give the agent a directly executable command even in an uninstalled source tree.
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCommand := shellQuote(executable) + " --url " + shellQuote(o.url)
|
||||
cmd, err := author.Command(ctx, o.opencode, d, o.prompt, cliCommand)
|
||||
if err != nil {
|
||||
return err
|
||||
var cmd *exec.Cmd
|
||||
if o.harness == "nvim" {
|
||||
cmd = exec.CommandContext(ctx, "nvim", d.Path)
|
||||
} else {
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCommand, err := harness.CLIPrefixFor(o.harness, o.url, executable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd, err = author.HarnessCommand(ctx, o.harness, d, o.prompt, cliCommand)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cmd.Stdin = a.In
|
||||
cmd.Stdout = a.Out
|
||||
@@ -918,14 +1014,20 @@ func (a App) finishRun(ctx context.Context, r protocol.Message, o *options, call
|
||||
if r.RunDetail == nil {
|
||||
return fmt.Errorf("server did not return run detail")
|
||||
}
|
||||
deadline := time.NewTimer(o.timeout)
|
||||
defer deadline.Stop()
|
||||
// The client wait limit is separate from the per-request --timeout.
|
||||
// Reaching it never cancels or replays admitted work; the run stays active.
|
||||
var deadline <-chan time.Time
|
||||
if o.waitTimeout > 0 {
|
||||
timer := time.NewTimer(o.waitTimeout)
|
||||
defer timer.Stop()
|
||||
deadline = timer.C
|
||||
}
|
||||
for r.RunDetail.Status == "running" || r.RunDetail.Status == "queued" {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-deadline.C:
|
||||
return fmt.Errorf("timed out waiting for run %d; it remains active", r.RunDetail.ID)
|
||||
case <-deadline:
|
||||
return fmt.Errorf("client wait limit reached for run %d; it remains active and was not canceled; inspect it read-only with pipelines inspect %d --json, and to keep waiting rerun with --wait reusing the original --request-key instead of starting a duplicate run", r.RunDetail.ID, r.RunDetail.ID)
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
r, err = call(protocol.Message{Type: protocol.GetRun, RunID: r.RunDetail.ID})
|
||||
@@ -946,4 +1048,35 @@ func (a App) finishRun(ctx context.Context, r protocol.Message, o *options, call
|
||||
return nil
|
||||
}
|
||||
|
||||
func shellQuote(value string) string { return "'" + strings.ReplaceAll(value, "'", "'\"'\"'") + "'" }
|
||||
// providerCheckDocker runs the provider check inside the profile's existing
|
||||
// Compose service so a Docker-linked profile never falls back to a host harness.
|
||||
// It streams the child's stdout/stderr and returns its exact exit code.
|
||||
func (a App) providerCheckDocker(ctx context.Context, o *options, profile harness.Profile) error {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{
|
||||
"compose", "--project-directory", profile.DockerDirectory,
|
||||
"exec", "-T", "--workdir", cwd,
|
||||
"pipelines", "pipelines", "provider-check",
|
||||
"--harness", o.harness, "--model", o.model, "--yes", "--timeout", o.timeout.String(),
|
||||
}
|
||||
// Preserve the caller's output mode: a plain-text invocation must stay
|
||||
// readable, while --json keeps the structured machine report.
|
||||
if o.json {
|
||||
args = append(args, "--json")
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "docker", args...)
|
||||
cmd.Stdin = a.In
|
||||
cmd.Stdout = a.Out
|
||||
cmd.Stderr = a.Err
|
||||
if err := cmd.Run(); err != nil {
|
||||
var exit *exec.ExitError
|
||||
if errors.As(err, &exit) {
|
||||
return &ExitError{Code: exit.ExitCode()}
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user