Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
install script and upgrade work
Dane Schneider990fa8eab1c9
diff --git a/app/cli/install.sh b/app/cli/install.shindex a8eea5ec..81954df5 100644--- a/app/cli/install.sh+++ b/app/cli/install.sh@@ -48,7 +48,7 @@ fi# Set Versionif [[ -z "${PLANDEX_VERSION}" ]]; then- VERSION=$(curl -s "https://api.github.com/repos/plandex-ai/plandex/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')+ VERSION=$(curl -sL https://plandex.ai/cli-version.txt)elseVERSION=$PLANDEX_VERSIONecho "Using custom version $VERSION"@@ -68,7 +68,9 @@ cleanup () {}download_plandex () {- url="${RELEASES_URL}/${VERSION}/plandex_${VERSION}_${PLATFORM}_${ARCH}.tar.gz"+ ENCODED_TAG="cli%2Fv${VERSION}"++ url="${RELEASES_URL}/${ENCODED_TAG}/plandex_${VERSION}_${PLATFORM}_${ARCH}.tar.gz"mkdir plandex_install_tmpcd plandex_install_tmpdiff --git a/app/cli/upgrade.go b/app/cli/upgrade.goindex e3031b1c..970a83db 100644--- a/app/cli/upgrade.go+++ b/app/cli/upgrade.go@@ -1,14 +1,18 @@package mainimport (+ "archive/tar"+ "compress/gzip""fmt""io""log""net/http"+ "net/url""os""os/exec""plandex/term""plandex/version"+ "runtime""github.com/Masterminds/semver""github.com/inconshreveable/go-update"@@ -62,17 +66,59 @@ func checkForUpgrade() {}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")+ tag := fmt.Sprintf("cli/v%s", version)+ escapedTag := url.QueryEscape(tag)++ downloadURL := fmt.Sprintf("https://github.com/plandex-ai/plandex/releases/download/%s/plandex_%s_%s_%s.tar.gz", escapedTag, version, runtime.GOOS, runtime.GOARCH)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{})+ // Create a temporary file to save the downloaded archive+ tempFile, err := os.CreateTemp("", "*.tar.gz")+ if err != nil {+ return fmt.Errorf("failed to create temporary file: %w", err)+ }+ defer os.Remove(tempFile.Name()) // Clean up file afterwards++ // Copy the response body to the temporary file+ _, err = io.Copy(tempFile, resp.Body)+ if err != nil {+ return fmt.Errorf("failed to save the downloaded archive: %w", err)+ }++ _, err = tempFile.Seek(0, 0)+ if err != nil {+ return fmt.Errorf("failed to seek in temporary file: %w", err)+ }++ // Now, extract the binary from the tempFile+ gzr, err := gzip.NewReader(tempFile)if err != nil {- return fmt.Errorf("failed to apply the update: %w", err)+ return fmt.Errorf("failed to create gzip reader: %w", err)+ }+ defer gzr.Close()++ tarReader := tar.NewReader(gzr)+ for {+ header, err := tarReader.Next()+ if err == io.EOF {+ break // End of archive+ }+ if err != nil {+ return fmt.Errorf("failed to read tar header: %w", err)+ }++ // Check if the current file is the binary+ if header.Typeflag == tar.TypeReg && (header.Name == "plandex" || header.Name == "plandex.exe") {+ err = update.Apply(tarReader, update.Options{})+ if err != nil {+ return fmt.Errorf("failed to apply update: %w", err)+ }+ break+ }}return nil