From eafe6f1702e3de3dc2c5dfb9a7c0261b8fae8d49 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 20 Oct 2026 15:10:54 +0100 Subject: [PATCH] opencode: find the CLI without trusting service PATH Fall back to Homebrew and local install locations when opencode is not on the service's minimal PATH, so a launchd/systemd restart cannot fail a run with exec: opencode not found. --- internal/opencode/connection.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/opencode/connection.go b/internal/opencode/connection.go index 801ded91..9172801e 100644 --- a/internal/opencode/connection.go +++ b/internal/opencode/connection.go @@ -102,10 +102,26 @@ func FromReference(path string) (*Connection, error) { return &Connection{Backend: "v1", URL: reference.URL, password: reference.Password, Directory: reference.Directory}, nil } +// Executable resolves the OpenCode CLI without trusting the service's PATH +// alone. A launchd/systemd service often starts with a minimal PATH, so an +// installed Homebrew or local binary must still be found; the absolute +// PIPELINES_OPENCODE override wins when the operator wants a specific build. func Executable() string { if path := os.Getenv("PIPELINES_OPENCODE"); path != "" { return path } + if path, err := exec.LookPath("opencode"); err == nil { + return path + } + candidates := []string{"/opt/homebrew/bin/opencode", "/usr/local/bin/opencode", "/usr/bin/opencode"} + if home, err := os.UserHomeDir(); err == nil { + candidates = append(candidates, filepath.Join(home, ".local", "bin", "opencode")) + } + for _, candidate := range candidates { + if info, err := os.Stat(candidate); err == nil && !info.IsDir() && info.Mode()&0o111 != 0 { + return candidate + } + } return "opencode" }