Skip to content

Commit

Permalink
if plan tell is stopped due to error or not updating context, output …
Browse files Browse the repository at this point in the history
…prompt before exiting so it isn't lost-fixes #109 and #182
  • Loading branch information
danenania committed Oct 2, 2024
1 parent c4d23d6 commit 7693757
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/cli/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func build(cmd *cobra.Command, args []string) {
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
ApiKeys: apiKeys,
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(false, maybeContexts)
},
}, buildBg)

Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func changes(cmd *cobra.Command, args []string) {
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
ApiKeys: apiKeys,
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(true, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(true, maybeContexts)
},
}, false)

Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/continue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func doContinue(cmd *cobra.Command, args []string) {
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
ApiKeys: apiKeys,
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(false, maybeContexts)
},
}, "", tellBg, tellStop, tellNoBuild, true)
}
4 changes: 2 additions & 2 deletions app/cli/cmd/tell.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func doTell(cmd *cobra.Command, args []string) {
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
ApiKeys: apiKeys,
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(false, maybeContexts)
},
}, prompt, tellBg, tellStop, tellNoBuild, false)
}
Expand Down
2 changes: 1 addition & 1 deletion app/cli/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func update(cmd *cobra.Command, args []string) {
return
}

lib.MustUpdateContext(nil)
lib.UpdateContextWithOutput(nil)
}
6 changes: 5 additions & 1 deletion app/cli/lib/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func MustApplyPlan(planId, branch string, autoConfirm bool) {
}
}

anyOutdated, didUpdate := MustCheckOutdatedContext(true, nil)
anyOutdated, didUpdate, err := CheckOutdatedContextWithOutput(true, nil)

if err != nil {
term.OutputErrorAndExit("error checking outdated context: %v", err)
}

if anyOutdated && !didUpdate {
term.StopSpinner()
Expand Down
21 changes: 12 additions & 9 deletions app/cli/lib/context_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
"github.com/plandex/plandex/shared"
)

func MustCheckOutdatedContext(quiet bool, maybeContexts []*shared.Context) (contextOutdated, updated bool) {
func CheckOutdatedContextWithOutput(quiet bool, maybeContexts []*shared.Context) (contextOutdated, updated bool, err error) {
if !quiet {
term.StartSpinner("🔬 Checking context...")
}

outdatedRes, err := CheckOutdatedContext(maybeContexts)
if err != nil {
term.StopSpinner()
term.OutputErrorAndExit("failed to check outdated context: %s", err)
return false, false, fmt.Errorf("failed to check outdated context: %s", err)
}

term.StopSpinner()
Expand All @@ -37,7 +37,7 @@ func MustCheckOutdatedContext(quiet bool, maybeContexts []*shared.Context) (cont
if !quiet {
fmt.Println("✅ Context is up to date")
}
return false, false
return false, false, nil
}
if len(outdatedRes.UpdatedContexts) > 0 {
types := []string{}
Expand Down Expand Up @@ -142,28 +142,31 @@ func MustCheckOutdatedContext(quiet bool, maybeContexts []*shared.Context) (cont
}

if confirmed {
MustUpdateContext(maybeContexts)
return true, true
err = UpdateContextWithOutput(maybeContexts)
if err != nil {
return false, false, fmt.Errorf("error updating context: %v", err)
}
return true, true, nil
} else {
return true, false
return true, false, nil
}

}

func MustUpdateContext(maybeUpdateContexts []*shared.Context) {
func UpdateContextWithOutput(maybeUpdateContexts []*shared.Context) error {
term.StartSpinner("🔄 Updating context...")

updateRes, err := UpdateContext(maybeUpdateContexts)

if err != nil {
term.StopSpinner()
term.OutputErrorAndExit("Error updating context: %v", err)
return err
}

term.StopSpinner()

fmt.Println("✅ " + updateRes.Msg)

return nil
}

func UpdateContext(maybeContexts []*shared.Context) (*types.ContextOutdatedResult, error) {
Expand Down
4 changes: 2 additions & 2 deletions app/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func init() {
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
ApiKeys: apiKeys,
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(true, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(true, maybeContexts)
},
}, false)
})
Expand Down
6 changes: 5 additions & 1 deletion app/cli/plan_exec/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func Build(params ExecParams, buildBg bool) (bool, error) {
term.OutputErrorAndExit("Error getting context: %v", apiErr)
}

anyOutdated, didUpdate := params.CheckOutdatedContext(contexts)
anyOutdated, didUpdate, err := params.CheckOutdatedContext(contexts)

if err != nil {
term.OutputErrorAndExit("error checking outdated context: %v", err)
}

if anyOutdated && !didUpdate {
term.StopSpinner()
Expand Down
2 changes: 1 addition & 1 deletion app/cli/plan_exec/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ type ExecParams struct {
CurrentPlanId string
CurrentBranch string
ApiKeys map[string]string
CheckOutdatedContext func(maybeContexts []*shared.Context) (bool, bool)
CheckOutdatedContext func(maybeContexts []*shared.Context) (bool, bool, error)
}
34 changes: 33 additions & 1 deletion app/cli/plan_exec/tell.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
streamtui "plandex/stream_tui"
"plandex/term"

"github.com/fatih/color"
"github.com/plandex/plandex/shared"
)

Expand All @@ -22,14 +23,34 @@ func TellPlan(
tellNoBuild,
isUserContinue bool,
) {

outputPromptIfTell := func() {
if isUserContinue || prompt == "" {
return
}

term.StopSpinner()
// print prompt so it isn't lost
color.New(term.ColorHiCyan, color.Bold).Println("\nYour prompt 👇")
fmt.Println()
fmt.Println(prompt)
fmt.Println()
}

term.StartSpinner("")
contexts, apiErr := api.Client.ListContext(params.CurrentPlanId, params.CurrentBranch)

if apiErr != nil {
outputPromptIfTell()
term.OutputErrorAndExit("Error getting context: %v", apiErr)
}

anyOutdated, didUpdate := params.CheckOutdatedContext(contexts)
anyOutdated, didUpdate, err := params.CheckOutdatedContext(contexts)

if err != nil {
outputPromptIfTell()
term.OutputErrorAndExit("Error checking outdated context: %v", err)
}

if anyOutdated && !didUpdate {
term.StopSpinner()
Expand All @@ -38,12 +59,17 @@ func TellPlan(
} else {
log.Println("Prompt not sent")
}

outputPromptIfTell()
color.New(term.ColorHiRed, color.Bold).Println("🛑 Plan won't continue due to outdated context")

os.Exit(0)
}

paths, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))

if err != nil {
outputPromptIfTell()
term.OutputErrorAndExit("Error getting project paths: %v", err)
}

Expand Down Expand Up @@ -98,6 +124,7 @@ func TellPlan(
res, err := term.ConfirmYesNo("Upgrade now?")

if err != nil {
outputPromptIfTell()
term.OutputErrorAndExit("Error prompting upgrade trial: %v", err)
}

Expand All @@ -106,9 +133,12 @@ func TellPlan(
// retry action after converting trial
return fn()
}

outputPromptIfTell()
return false
}

outputPromptIfTell()
term.OutputErrorAndExit("Prompt error: %v", apiErr.Msg)
} else if apiErr != nil && isUserContinue && apiErr.Type == shared.ApiErrorTypeContinueNoMessages {
fmt.Println("🤷‍♂️ There's no plan yet to continue")
Expand All @@ -122,6 +152,7 @@ func TellPlan(
err := streamtui.StartStreamUI(prompt, false)

if err != nil {
outputPromptIfTell()
term.OutputErrorAndExit("Error starting stream UI: %v", err)
}

Expand All @@ -145,6 +176,7 @@ func TellPlan(
}

if tellBg {
outputPromptIfTell()
fmt.Println("✅ Plan is active in the background")
fmt.Println()
term.PrintCmds("", "ps", "connect", "stop")
Expand Down
8 changes: 4 additions & 4 deletions app/cli/term/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func ConfirmYesNo(fmtStr string, fmtArgs ...interface{}) (bool, error) {
return false, fmt.Errorf("failed to get user input: %s", err)
}

// ctrl+c == no
if key == keyboard.KeyCtrlC {
fmt.Println()
os.Exit(0)
return false, nil
}

fmt.Println(string(char))
Expand All @@ -99,9 +99,9 @@ func ConfirmYesNoCancel(fmtStr string, fmtArgs ...interface{}) (bool, bool, erro
return false, false, fmt.Errorf("failed to get user input: %s", err)
}

// ctrl+c == cancel
if key == keyboard.KeyCtrlC {
fmt.Println()
os.Exit(0)
return false, true, nil
}

fmt.Println(string(char))
Expand Down
2 changes: 2 additions & 0 deletions test/pong/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void init() {
initBall();
}



void display() {
glClear(GL_COLOR_BUFFER_BIT);
renderPaddle();
Expand Down

0 comments on commit 7693757

Please sign in to comment.