Skip to content

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

πŸ€– Plandex β†’ Add support for renaming and archiving plans

Dane Schneider0d0dc10a4f17
diff --git a/app/cli/cmd/archive.go b/app/cli/cmd/archive.go
new file mode 100644
index 00000000..71ee8da1
--- /dev/null
+++ b/app/cli/cmd/archive.go
@@ -0,0 +1,94 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "plandex/api"
+ "plandex/auth"
+ "plandex/lib"
+ "plandex/term"
+ "strconv"
+ "strings"
+
+ "github.com/fatih/color"
+ "github.com/spf13/cobra"
+)
+
+var archiveCmd = &cobra.Command{
+ Use: "archive [name-or-index]",
+ Aliases: []string{"ar"},
+ Short: "Archive a plan",
+ Args: cobra.MaximumNArgs(1),
+ Run: archive,
+}
+
+func init() {
+ RootCmd.AddCommand(archiveCmd)
+}
+
+func archive(cmd *cobra.Command, args []string) {
+ auth.MustResolveAuthWithOrg()
+ lib.MustResolveProject()
+
+ var nameOrIdx string
+ if len(args) > 0 {
+ nameOrIdx = strings.TrimSpace(args[0])
+ }
+
+ var plan *shared.Plan
+
+ term.StartSpinner("Loading plans")
+ plans, apiErr := api.Client.ListPlans([]string{lib.CurrentProjectId})
+ term.StopSpinner()
+
+ if apiErr != nil {
+ term.OutputErrorAndExit("Error getting plans: %v", apiErr)
+ }
+
+ if len(plans) == 0 {
+ fmt.Println("πŸ€·β€β™‚οΈ No plans available to archive")
+ return
+ }
+
+ if nameOrIdx == "" {
+ opts := make([]string, len(plans))
+ for i, p := range plans {
+ opts[i] = p.Name
+ }
+
+ selected, err := term.SelectFromList("Select a plan to archive", opts)
+ if err != nil {
+ term.OutputErrorAndExit("Error selecting plan: %v", err)
+ }
+
+ for _, p := range plans {
+ if p.Name == selected {
+ plan = p
+ break
+ }
+ }
+ } else {
+ idx, err := strconv.Atoi(nameOrIdx)
+ if err == nil && idx > 0 && idx <= len(plans) {
+ plan = plans[idx-1]
+ } else {
+ for _, p := range plans {
+ if p.Name == nameOrIdx {
+ plan = p
+ break
+ }
+ }
+ }
+ }
+
+ if plan == nil {
+ term.OutputErrorAndExit("Plan not found")
+ }
+
+ err := api.Client.ArchivePlan(plan.Id)
+ if err != nil {
+ term.OutputErrorAndExit("Error archiving plan: %v", err)
+ }
+
+ fmt.Printf("βœ… Plan %s archived successfully\n", color.New(color.Bold).Sprint(plan.Name))
+}
diff --git a/app/cli/cmd/rename.go b/app/cli/cmd/rename.go
new file mode 100644
index 00000000..34f78c15
--- /dev/null
+++ b/app/cli/cmd/rename.go
@@ -0,0 +1,55 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "plandex/api"
+ "plandex/auth"
+ "plandex/lib"
+ "plandex/term"
+
+ "github.com/spf13/cobra"
+)
+
+var renameCmd = &cobra.Command{
+ Use: "rename [new-name]",
+ Aliases: []string{"rn"},
+ Short: "Rename the current plan",
+ Args: cobra.MaximumNArgs(1),
+ Run: rename,
+}
+
+func init() {
+ RootCmd.AddCommand(renameCmd)
+}
+
+func rename(cmd *cobra.Command, args []string) {
+ auth.MustResolveAuthWithOrg()
+ lib.MustResolveProject()
+
+ var newName string
+ if len(args) > 0 {
+ newName = args[0]
+ } else {
+ var err error
+ newName, err = term.Prompt("Enter new name for the current plan:")
+ if err != nil {
+ term.OutputErrorAndExit("Error reading new name: %v", err)
+ }
+ }
+
+ if newName == "" {
+ fmt.Println("No new name provided.")
+ return
+ }
+
+ term.StartSpinner("Renaming plan")
+ err := api.Client.RenamePlan(lib.CurrentPlanId, newName)
+ term.StopSpinner()
+
+ if err != nil {
+ term.OutputErrorAndExit("Error renaming plan: %v", err)
+ }
+
+ fmt.Printf("βœ… Plan renamed to %s\n", newName)
+}