Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

🤖 Plandex → apply pending changes ✏️ Refactor version handling to a separate package and implement version check on startup ✏️ Update .goreleaser.yml to reference new location of Version variable ✏️ Implement upgrade functionality in Plandex CLI tool

Dane Schneider9dc3b7f8ada6
diff --git a/app/cli/main.go b/app/cli/main.go
index f704f036..21cba856 100644
--- a/app/cli/main.go
+++ b/app/cli/main.go
@@ -1,8 +1,11 @@
package main
-import (
+ "fmt"
+ "io/ioutil"
"log"
+ "net/http"
"os"
+ "os/exec"
"path/filepath"
"plandex/api"
"plandex/auth"
@@ -11,11 +14,16 @@ import (
"plandex/lib"
"plandex/plan_exec"
"plandex/term"
-
+ "plandex/version"
+ "github.com/inconshreveable/go-update"
"github.com/plandex/plandex/shared"
+
)
func init() {
+ // Version check and prompt for upgrade
+ go checkForUpgrade()
+
// inter-package dependency injections to avoid circular imports
auth.SetApiClient(api.Client)
lib.SetBuildPlanInlineFn(func(maybeContexts []*shared.Context) (bool, error) {
@@ -24,7 +32,38 @@ func init() {
CurrentBranch: lib.CurrentBranch,
CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
return lib.MustCheckOutdatedContext(cancelOpt, true, maybeContexts)
- },
+ func doUpgrade(version string) error {
+ // Placeholder for download URL. This should point to the actual binary location.
+ downloadURL := fmt.Sprintf("https://github.com/plandex-ai/plandex/releases/download/%s/plandex_%s_%s_%s.tar.gz", version, version, "os", "arch")
+ resp, err := http.Get(downloadURL)
+ if err != nil {
+ return fmt.Errorf("failed to download the update: %w", err)
+ }
+ defer resp.Body.Close()
+
+ err = update.Apply(resp.Body, update.Options{})
+ if err != nil {
+ return fmt.Errorf("failed to apply the update: %w", err)
+ }
+
+ return nil
+}
+
+func restartPlandex() {
+ exe, err := os.Executable()
+ if err != nil {
+ log.Fatalf("Failed to determine executable path: %v", err)
+ }
+
+ cmd := exec.Command(exe, os.Args[1:]...)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ err = cmd.Start()
+ if err != nil {
+ log.Fatalf("Failed to restart: %v", err)
+ }
+ os.Exit(0)
+},
}, false)
})
@@ -42,6 +81,43 @@ func init() {
// log.Println("Starting Plandex - logging initialized")
}
+func checkForUpgrade() {
+ latestVersionURL := "https://example.com/plandex/latest-version" // Placeholder URL
+ resp, err := http.Get(latestVersionURL)
+ if err != nil {
+ log.Println("Error checking latest version:", err)
+ return
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ log.Println("Error reading response body:", err)
+ return
+ }
+
+ latestVersion := string(body)
+ if latestVersion > version.Version {
+ fmt.Println("A new version of Plandex is available:", latestVersion)
+ confirmed, err := term.ConfirmYesNo("Do you want to upgrade to the latest version?")
+ if err != nil {
+ log.Println("Error reading input:", err)
+ return
+ }
+
+ if confirmed {
+ err := doUpgrade(latestVersion)
+ if err != nil {
+ log.Println("Upgrade failed:", err)
+ return
+ }
+ fmt.Println("Upgrade successful. Restarting Plandex...")
+ restartPlandex()
+ }
+ }
+}
+}
+
func main() {
cmd.Execute()
}