Skip to content

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

some tweaks to cd/checkout/delete-branch/delete-plan selection by index, name, or select prompt; also some cleanup and fixes

Dane Schneider8d36d4ab2213
diff --git a/app/cli/api/stream.go b/app/cli/api/stream.go
index 25415559..0119c89c 100644
--- a/app/cli/api/stream.go
+++ b/app/cli/api/stream.go
@@ -33,7 +33,7 @@ func connectPlanRespStream(body io.ReadCloser, onStream types.OnStreamPlan) {
return
}
- log.Println("Received message:", msg)
+ // log.Println("Received message:", msg)
onStream(types.OnStreamPlanParams{Msg: &msg, Err: nil})
diff --git a/app/cli/cmd/branches.go b/app/cli/cmd/branches.go
index c7b5125e..14816456 100644
--- a/app/cli/cmd/branches.go
+++ b/app/cli/cmd/branches.go
@@ -47,16 +47,20 @@ func branches(cmd *cobra.Command, args []string) {
table.SetHeader([]string{"#", "Name", "Updated", "Created", "Context", "Convo"})
for i, b := range branches {
+ num := strconv.Itoa(i + 1)
+ if b.Name == lib.CurrentBranch {
+ num = color.New(color.Bold, color.FgGreen).Sprint(num)
+ }
var name string
- if b.Id == lib.CurrentPlanId {
+ if b.Name == lib.CurrentBranch {
name = color.New(color.Bold, color.FgGreen).Sprint(b.Name) + color.New(color.FgWhite).Sprint(" πŸ‘ˆ current")
} else {
name = b.Name
}
row := []string{
- strconv.Itoa(i + 1),
+ num,
name,
format.Time(b.UpdatedAt),
format.Time(b.CreatedAt),
@@ -80,8 +84,7 @@ func branches(cmd *cobra.Command, args []string) {
}
table.Render()
-
fmt.Println()
- term.PrintCmds("", "checkout")
+ term.PrintCmds("", "checkout", "delete-branch")
}
diff --git a/app/cli/cmd/cd.go b/app/cli/cmd/cd.go
index 235894b1..344a4170 100644
--- a/app/cli/cmd/cd.go
+++ b/app/cli/cmd/cd.go
@@ -8,6 +8,7 @@ import (
"plandex/lib"
"plandex/term"
"strconv"
+ "strings"
"time"
"github.com/fatih/color"
@@ -23,7 +24,7 @@ var cdCmd = &cobra.Command{
Use: "cd [name-or-index]",
Aliases: []string{"set-plan"},
Short: "Set current plan by name or index",
- Args: cobra.ExactArgs(1),
+ Args: cobra.MaximumNArgs(1),
Run: cd,
}
@@ -31,7 +32,11 @@ func cd(cmd *cobra.Command, args []string) {
auth.MustResolveAuthWithOrg()
lib.MustResolveProject()
- nameOrIdx := args[0]
+ var nameOrIdx string
+ if len(args) > 0 {
+ nameOrIdx = strings.TrimSpace(args[0])
+ }
+
var plan *shared.Plan
plans, apiErr := api.Client.ListPlans(lib.CurrentProjectId)
@@ -41,31 +46,60 @@ func cd(cmd *cobra.Command, args []string) {
os.Exit(1)
}
- // see if it's an index
- idx, err := strconv.Atoi(nameOrIdx)
+ if len(plans) == 0 {
+ fmt.Println("πŸ€·β€β™‚οΈ No plans")
+ fmt.Println()
+ term.PrintCmds("", "new")
+ return
+ }
- if err == nil {
- if idx > 0 && idx <= len(plans) {
- plan = plans[idx-1]
- } else {
- fmt.Fprintln(os.Stderr, "Error: index out of range")
- os.Exit(1)
+ if nameOrIdx == "" {
+
+ opts := make([]string, len(plans))
+ for i, plan := range plans {
+ opts[i] = plan.Name
}
- } else {
+
+ selected, err := term.SelectFromList("Select a plan", opts)
+
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error selecting plan:", err)
+ return
+ }
+
for _, p := range plans {
- if p.Name == nameOrIdx {
+ if p.Name == selected {
plan = p
break
}
}
-
- if plan == nil {
- fmt.Fprintln(os.Stderr, "Error: plan not found")
- os.Exit(1)
+ } else {
+ // see if it's an index
+ idx, err := strconv.Atoi(nameOrIdx)
+
+ if err == nil {
+ if idx > 0 && idx <= len(plans) {
+ plan = plans[idx-1]
+ } else {
+ fmt.Fprintln(os.Stderr, "Error: index out of range")
+ os.Exit(1)
+ }
+ } else {
+ for _, p := range plans {
+ if p.Name == nameOrIdx {
+ plan = p
+ break
+ }
+ }
}
}
- err = lib.WriteCurrentPlan(plan.Id)
+ if plan == nil {
+ fmt.Fprintln(os.Stderr, "🚨 Plan not found")
+ os.Exit(1)
+ }
+
+ err := lib.WriteCurrentPlan(plan.Id)
if err != nil {
fmt.Fprintln(os.Stderr, "Error setting current plan:", err)
os.Exit(1)
diff --git a/app/cli/cmd/checkout.go b/app/cli/cmd/checkout.go
index 0d34e1fc..78a51597 100644
--- a/app/cli/cmd/checkout.go
+++ b/app/cli/cmd/checkout.go
@@ -7,6 +7,7 @@ import (
"plandex/auth"
"plandex/lib"
"plandex/term"
+ "strconv"
"strings"
"github.com/fatih/color"
@@ -19,7 +20,7 @@ const (
)
var checkoutCmd = &cobra.Command{
- Use: "checkout",
+ Use: "checkout [name-or-index]",
Aliases: []string{"co"},
Short: "Checkout an existing plan branch or create a new one",
Run: checkout,
@@ -39,6 +40,14 @@ func checkout(cmd *cobra.Command, args []string) {
return
}
+ branchName := ""
+ willCreate := false
+
+ var nameOrIdx string
+ if len(args) > 0 {
+ nameOrIdx = strings.TrimSpace(args[0])
+ }
+
branches, apiErr := api.Client.ListBranches(lib.CurrentPlanId)
if apiErr != nil {
@@ -46,13 +55,7 @@ func checkout(cmd *cobra.Command, args []string) {
return
}
- branchName := ""
- willCreate := false
- if len(args) > 0 {
- branchName = strings.TrimSpace(args[0])
- }
-
- if branchName == "" {
+ if nameOrIdx == "" {
opts := make([]string, len(branches))
for i, branch := range branches {
opts[i] = branch.Name
@@ -76,11 +79,29 @@ func checkout(cmd *cobra.Command, args []string) {
} else {
branchName = selected
}
+ } else {
+ // see if it's an index
+ idx, err := strconv.Atoi(nameOrIdx)
+
+ if err == nil {
+ if idx > 0 && idx <= len(branches) {
+ branchName = branches[idx-1].Name
+ } else {
+ fmt.Fprintln(os.Stderr, "Error: index out of range")
+ os.Exit(1)
+ }
+ } else {
+ for _, b := range branches {
+ if b.Name == nameOrIdx {
+ branchName = b.Name
+ break
+ }
+ }
+ }
}
if branchName == "" {
- // should never happen
- fmt.Fprintln(os.Stderr, "🚨 Error selecting branch")
+ fmt.Fprintln(os.Stderr, "🚨 Branch not found")
os.Exit(1)
}
diff --git a/app/cli/cmd/delete_branch.go b/app/cli/cmd/delete_branch.go
index 3ab199b6..76c18210 100644
--- a/app/cli/cmd/delete_branch.go
+++ b/app/cli/cmd/delete_branch.go
@@ -2,10 +2,12 @@ package cmd
import (
"fmt"
+ "os"
"plandex/api"
"plandex/auth"
"plandex/lib"
"plandex/term"
+ "strconv"
"strings"
"github.com/spf13/cobra"
@@ -13,9 +15,10 @@ import (
var deleteBranchCmd = &cobra.Command{
Use: "delete-branch",
- Aliases: []string{""},
- Short: "Delete a plan branch",
+ Aliases: []string{"db"},
+ Short: "Delete a plan branch by name or index",
Run: deleteBranch,
+ Args: cobra.MaximumNArgs(1),
}
func init() {
@@ -31,9 +34,14 @@ func deleteBranch(cmd *cobra.Command, args []string) {
return
}
- branch := strings.TrimSpace(args[0])
+ var branch string
+ var nameOrIdx string
- if branch == "main" {
+ if len(args) > 0 {
+ nameOrIdx = strings.TrimSpace(args[0])
+ }
+
+ if nameOrIdx == "main" {
fmt.Println("🚨 Cannot delete main branch")
return
}
@@ -45,7 +53,7 @@ func deleteBranch(cmd *cobra.Command, args []string) {
return
}
- if branch == "" {
+ if nameOrIdx == "" {
opts := make([]string, len(branches))
for i, branch := range branches {
if branch.Name == "main" {
@@ -69,6 +77,30 @@ func deleteBranch(cmd *cobra.Command, args []string) {
branch = sel
}
+ // see if it's an index
+ idx, err := strconv.Atoi(nameOrIdx)
+
+ if err == nil {
+ if idx > 0 && idx <= len(branches) {
+ branch = branches[idx-1].Name
+ } else {
+ fmt.Fprintln(os.Stderr, "Error: index out of range")
+ os.Exit(1)
+ }
+ } else {
+ for _, b := range branches {
+ if b.Name == nameOrIdx {
+ branch = b.Name
+ break
+ }
+ }
+
+ if branch == "" {
+ fmt.Fprintln(os.Stderr, "Error: branch not found")
+ os.Exit(1)
+ }
+ }
+
found := false
for _, b := range branches {
if b.Name == branch {
@@ -82,10 +114,10 @@ func deleteBranch(cmd *cobra.Command, args []string) {
return
}
- err := api.Client.DeleteBranch(lib.CurrentPlanId, branch)
+ apiErr = api.Client.DeleteBranch(lib.CurrentPlanId, branch)
- if err != nil {
- fmt.Println("Error deleting branch:", err)
+ if apiErr != nil {
+ fmt.Println("Error deleting branch:", apiErr)
return
}
diff --git a/app/cli/cmd/delete_plan.go b/app/cli/cmd/delete_plan.go
index c42c68c8..9c8ee805 100644
--- a/app/cli/cmd/delete_plan.go
+++ b/app/cli/cmd/delete_plan.go
@@ -4,10 +4,12 @@ import (
"fmt"
"os"
"strconv"
+ "strings"
"plandex/api"
"plandex/auth"
"plandex/lib"
+ "plandex/term"
"github.com/fatih/color"
"github.com/plandex/plandex/shared"
@@ -24,7 +26,7 @@ func init() {
// rmCmd represents the rm command
var rmCmd = &cobra.Command{
Use: "delete-plan [name-or-index]",
- Aliases: []string{"del"},
+ Aliases: []string{"dp"},
Short: "Delete a plan by name or index, or delete all plans with --all flag",
Args: cobra.RangeArgs(0, 1),
Run: del,
@@ -39,7 +41,15 @@ func del(cmd *cobra.Command, args []string) {
return
}
- nameOrIdx := args[0]
+ var nameOrIdx string
+ if len(args) > 0 {
+ nameOrIdx = strings.TrimSpace(args[0])
+
+ if all {
+ fmt.Fprintln(os.Stderr, "🚨 Can't use both --all and a plan name or index")
+ return
+ }
+ }
var plan *shared.Plan
plans, apiErr := api.Client.ListPlans(lib.CurrentProjectId)
@@ -49,30 +59,60 @@ func del(cmd *cobra.Command, args []string) {
os.Exit(1)
}
- // see if it's an index
- idx, err := strconv.Atoi(nameOrIdx)
+ if len(plans) == 0 {
+ fmt.Println("πŸ€·β€β™‚οΈ No plans")
+ fmt.Println()
+ term.PrintCmds("", "new")
+ return
+ }
+
+ if nameOrIdx == "" {
- if err == nil {
- if idx > 0 && idx <= len(plans) {
- plan = plans[idx-1]
- } else {
- fmt.Fprintln(os.Stderr, "Error: index out of range")
- os.Exit(1)
+ opts := make([]string, len(plans))
+ for i, plan := range plans {
+ opts[i] = plan.Name
}
- } else {
+
+ selected, err := term.SelectFromList("Select a plan", opts)
+
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error selecting plan:", err)
+ return
+ }
+
for _, p := range plans {
- if p.Name == nameOrIdx {
+ if p.Name == selected {
plan = p
break
}
}
+ } else {
+
+ // see if it's an index
+ idx, err := strconv.Atoi(nameOrIdx)
- if plan == nil {
- fmt.Fprintln(os.Stderr, "Error: plan not found")
- os.Exit(1)
+ if err == nil {
+ if idx > 0 && idx <= len(plans) {
+ plan = plans[idx-1]
+ } else {
+ fmt.Fprintln(os.Stderr, "Error: index out of range")
+ os.Exit(1)
+ }
+ } else {
+ for _, p := range plans {
+ if p.Name == nameOrIdx {
+ plan = p
+ break
+ }
+ }
}
}
+ if plan == nil {
+ fmt.Fprintln(os.Stderr, "🚨 Plan not found")
+ os.Exit(1)
+ }
+
apiErr = api.Client.DeletePlan(plan.Id)
if apiErr != nil {
@@ -81,7 +121,7 @@ func del(cmd *cobra.Command, args []string) {
}
if lib.CurrentPlanId == plan.Id {
- err = lib.ClearCurrentPlan()
+ err := lib.ClearCurrentPlan()
if err != nil {
fmt.Fprintln(os.Stderr, "Error clearing current plan:", err)
return
diff --git a/app/cli/cmd/plans.go b/app/cli/cmd/plans.go
index e7cce40a..3160b10e 100644
--- a/app/cli/cmd/plans.go
+++ b/app/cli/cmd/plans.go
@@ -73,6 +73,10 @@ func plans(cmd *cobra.Command, args []string) {
table.SetHeader([]string{"#", "Name", "Updated", "Created" /*"Branches",*/, "Branch", "Context", "Convo"})
for i, p := range plans {
+ num := strconv.Itoa(i + 1)
+ if p.Id == lib.CurrentPlanId {
+ num = color.New(color.Bold, color.FgGreen).Sprint(num)
+ }
var name string
if p.Id == lib.CurrentPlanId {
@@ -84,7 +88,7 @@ func plans(cmd *cobra.Command, args []string) {
currentBranch := currentBranchesByPlanId[p.Id]
row := []string{
- strconv.Itoa(i + 1),
+ num,
name,
format.Time(p.UpdatedAt),
format.Time(p.CreatedAt),
@@ -111,5 +115,5 @@ func plans(cmd *cobra.Command, args []string) {
}
table.Render()
fmt.Println()
- term.PrintCmds("", "new", "cd", "delete-plan")
+ term.PrintCmds("", "tell", "new", "cd", "delete-plan")
}
diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.go
index a472c0f5..212c75c6 100644
--- a/app/cli/stream_tui/update.go
+++ b/app/cli/stream_tui/update.go
@@ -115,12 +115,12 @@ func (m *streamUIModel) updateReplyDisplay() {
promptTxt, _ := term.GetPlain(m.prompt)
s := color.New(color.BgGreen, color.Bold, color.FgHiWhite).Sprintf(" πŸ’¬ User prompt πŸ‘‡ ")
- s += "\n" + promptTxt
+ s += "\n\n" + strings.TrimSpace(promptTxt) + "\n"
if m.reply != "" {
replyMd, _ := term.GetMarkdown(m.reply)
s += "\n\n" + color.New(color.BgBlue, color.Bold, color.FgHiWhite).Sprintf(" πŸ€– Plandex reply πŸ‘‡ ")
- s += "\n" + strings.TrimSpace(replyMd) + "\n"
+ s += "\n\n" + strings.TrimSpace(replyMd) + "\n"
} else {
s += "\n"
}
diff --git a/app/cli/term/term.go b/app/cli/term/term.go
index f0ec2c3e..315ea80c 100644
--- a/app/cli/term/term.go
+++ b/app/cli/term/term.go
@@ -26,17 +26,18 @@ var CmdDesc = map[string][2]string{
"apply": {"ap", "apply the plan to your project files"},
"continue": {"c", "continue the plan"},
// "status": {"s", "show status of the plan"},
- "rewind": {"rw", "rewind to a previous state"},
- "ls": {"", "list everything in context"},
- "rm": {"", "remove context by name, index, or glob"},
- "clear": {"", "remove all context"},
- "delete-plan": {"del", "delete plan by name or index"},
- "plans": {"pl", "list plans"},
- "update": {"u", "update outdated context"},
- "log": {"", "show log of plan updates"},
- "convo": {"", "show plan conversation"},
- "branches": {"br", "list plan branches"},
- // "checkout": {"co", "checkout or create a branch"}, need to implement non-contiguous aliases
+ "rewind": {"rw", "rewind to a previous state"},
+ "ls": {"", "list everything in context"},
+ "rm": {"", "remove context by name, index, or glob"},
+ "clear": {"", "remove all context"},
+ "delete-plan": {"dp", "delete plan by name or index"},
+ "delete-branch": {"db", "delete a branch by name or index"},
+ "plans": {"pl", "list plans"},
+ "update": {"u", "update outdated context"},
+ "log": {"", "show log of plan updates"},
+ "convo": {"", "show plan conversation"},
+ "branches": {"br", "list plan branches"},
+ "checkout": {"co", "checkout or create a branch"},
}
func PrintCmds(prefix string, cmds ...string) {
@@ -49,7 +50,14 @@ func PrintCmds(prefix string, cmds ...string) {
alias := config[0]
desc := config[1]
if alias != "" {
- cmd = strings.Replace(cmd, alias, fmt.Sprintf("(%s)", alias), 1)
+ containsFull := strings.Contains(cmd, alias)
+
+ if containsFull {
+ cmd = strings.Replace(cmd, alias, fmt.Sprintf("(%s)", alias), 1)
+ } else {
+ cmd = fmt.Sprintf("%s (%s)", cmd, alias)
+ }
+
// desc += color.New(color.FgWhite).Sprintf(" β€’ alias β†’ %s", color.New(color.Bold).Sprint(alias))
}
styled := color.New(color.Bold, color.FgHiWhite, color.BgCyan).Sprintf(" plandex %s ", cmd)
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index 80065e4b..88ea5e6f 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -25,10 +25,16 @@ func ExecStatusShouldContinue(client *openai.Client, message string, ctx context
if strings.Contains(lastParagraph, "All tasks have been completed") ||
strings.Contains(lastParagraph, "all tasks have been completed") ||
strings.Contains(lastParagraph, "plan cannot be continued") {
+
+ log.Println("Plan cannot be continued based on last paragraph")
+
return false, nil
}
if strings.Index(lastParagraph, "Next, ") < 3 {
+
+ log.Println("Plan can be continued based on last paragraph")
+
return true, nil
}
}
@@ -40,6 +46,8 @@ func ExecStatusShouldContinue(client *openai.Client, message string, ctx context
},
}
+ log.Println("Calling model to check if plan should continue")
+
resp, err := client.CreateChatCompletion(
ctx,
openai.ChatCompletionRequest{
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index d75b1e74..051a61fc 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -9,7 +9,6 @@ import (
"plandex-server/db"
"time"
- "github.com/davecgh/go-spew/spew"
"github.com/google/uuid"
"github.com/plandex/plandex/shared"
)
@@ -217,8 +216,8 @@ func (ap *ActivePlan) PendingBuildsByPath(orgId, userId string, convoMessagesArg
}
}
- log.Println("planDescs:")
- spew.Dump(planDescs)
+ // log.Println("planDescs:")
+ // spew.Dump(planDescs)
activeBuildsByPath := map[string][]*ActiveBuild{}
@@ -249,8 +248,8 @@ func (ap *ActivePlan) PendingBuildsByPath(orgId, userId string, convoMessagesArg
}
}
- log.Println("activeBuildsByPath:")
- spew.Dump(activeBuildsByPath)
+ // log.Println("activeBuildsByPath:")
+ // spew.Dump(activeBuildsByPath)
return activeBuildsByPath, nil
}