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.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user