From 37e2d37cf4c16a8c292414a08196c6b65ce92949 Mon Sep 17 00:00:00 2001 From: Keith Patrick Date: Thu, 11 Jun 2026 13:34:49 +0100 Subject: [PATCH] feat: implement pkg-helper fallback execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add CLI argument support to pkg-helper and fallback execution via $PATH in dep_installer when the Unix socket is unavailable. 💘 Generated with Crush Assisted-by: Crush:gemini-3.1-pro-preview-customtools --- cmd/pkg-helper/main.go | 14 ++++++++++++++ internal/skills/dep_installer.go | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/cmd/pkg-helper/main.go b/cmd/pkg-helper/main.go index bfebf715..b9962c22 100644 --- a/cmd/pkg-helper/main.go +++ b/cmd/pkg-helper/main.go @@ -60,6 +60,20 @@ type response struct { } func main() { + if len(os.Args) > 1 { + req := request{Action: os.Args[1]} + if len(os.Args) > 2 { + req.Package = os.Args[2] + } + resp := handleRequest(req) + out, _ := json.Marshal(resp) + fmt.Println(string(out)) + if !resp.OK { + os.Exit(1) + } + return + } + slog.Info("pkg-helper: starting", "socket", socketPath, "protocol", "v2") // Remove stale socket. diff --git a/internal/skills/dep_installer.go b/internal/skills/dep_installer.go index 0628b0ba..7f7bfe71 100644 --- a/internal/skills/dep_installer.go +++ b/internal/skills/dep_installer.go @@ -305,6 +305,33 @@ func UninstallPackage(ctx context.Context, dep string) (bool, string) { func apkHelperCall(ctx context.Context, action, pkg string) (ok bool, code, data, errMsg string) { conn, err := net.DialTimeout("unix", pkgHelperSocket, 5*time.Second) if err != nil { + // Fallback: try executing pkg-helper directly if available + if path, lookErr := exec.LookPath("pkg-helper"); lookErr == nil { + cmd := exec.CommandContext(ctx, path, action) + if pkg != "" { + cmd.Args = append(cmd.Args, pkg) + } + out, execErr := cmd.CombinedOutput() + + var resp struct { + OK bool `json:"ok"` + Error string `json:"error"` + Code string `json:"code"` + Data string `json:"data"` + } + if unmarshalErr := json.Unmarshal(out, &resp); unmarshalErr == nil { + if resp.Code == "" && !resp.OK { + resp.Code = "system_error" + } + return resp.OK, resp.Code, resp.Data, resp.Error + } + + if execErr != nil { + return false, "system_error", "", fmt.Sprintf("pkg-helper fallback failed: %v: %s", execErr, strings.TrimSpace(string(out))) + } + return true, "", string(out), "" + } + return false, "helper_unavailable", "", fmt.Sprintf("pkg-helper unavailable: %v", err) } defer conn.Close()