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
sign-in command, better handling of prompt interrupts
Dane Schneider690180dacb26
diff --git a/app/cli/auth/account.go b/app/cli/auth/account.goindex c0394f55..4b2b0a13 100644--- a/app/cli/auth/account.go+++ b/app/cli/auth/account.go@@ -5,6 +5,7 @@ import ("plandex/term""plandex/types"+ "github.com/fatih/color""github.com/plandex/plandex/shared")@@ -29,7 +30,7 @@ func promptInitialAuth() error {}case AuthAccountOption:- err = selectOrSignInOrCreate()+ err = SelectOrSignInOrCreate()if err != nil {return fmt.Errorf("error selecting or signing in to account: %v", err)@@ -41,7 +42,7 @@ func promptInitialAuth() error {const AddAccountOption = "Add another account"-func selectOrSignInOrCreate() error {+func SelectOrSignInOrCreate() error {accounts, err := loadAccounts()if err != nil {@@ -90,6 +91,10 @@ func selectOrSignInOrCreate() error {return fmt.Errorf("error selecting account: account not found")}+ setAuth(&types.ClientAuth{+ ClientAccount: *selected,+ })+term.StartSpinner("")orgs, apiErr := apiClient.ListOrgs()term.StopSpinner()@@ -114,6 +119,11 @@ func selectOrSignInOrCreate() error {return fmt.Errorf("error setting auth: %v", err)}+ fmt.Printf("β Signed in as %s | Org: %s\n", color.New(color.Bold, color.FgHiGreen).Sprintf("<%s> %s", Current.UserName, Current.Email), color.New(color.FgHiCyan).Sprint(Current.OrgName))+ fmt.Println()++ term.PrintCmds("", "new", "plans")+return nil}diff --git a/app/cli/cmd/sign_in.go b/app/cli/cmd/sign_in.goindex 0ddf3d44..89a5cc39 100644--- a/app/cli/cmd/sign_in.go+++ b/app/cli/cmd/sign_in.go@@ -1,6 +1,11 @@package cmd-import "github.com/spf13/cobra"+import (+ "plandex/auth"+ "plandex/term"++ "github.com/spf13/cobra"+)var signInCmd = &cobra.Command{Use: "sign-in",@@ -14,5 +19,9 @@ func init() {}func signIn(cmd *cobra.Command, args []string) {+ err := auth.SelectOrSignInOrCreate()+ if err != nil {+ term.OutputErrorAndExit("Error signing in: %v", err)+ }}diff --git a/app/cli/stream_tui/run.go b/app/cli/stream_tui/run.goindex 5f286400..600d0e62 100644--- a/app/cli/stream_tui/run.go+++ b/app/cli/stream_tui/run.go@@ -3,6 +3,7 @@ package streamtuiimport ("fmt""log"+ "plandex/term""sync"tea "github.com/charmbracelet/bubbletea"@@ -45,20 +46,24 @@ func StartStreamUI(prompt string, buildOnly bool) error {if mod.err != nil {fmt.Println()- color.New(color.FgHiRed, color.Bold).Printf("error in stream UI: %v\n", mod.err)- return fmt.Errorf("error in stream UI: %v", mod.err)+ term.OutputErrorAndExit(mod.err.Error())}if mod.apiErr != nil {fmt.Println()- color.New(color.FgHiRed, color.Bold).Printf("error in stream UI: %s\n", mod.apiErr.Msg)- return fmt.Errorf("error in stream UI: %v", mod.apiErr)+ term.OutputErrorAndExit(mod.apiErr.Msg)}if mod.stopped {fmt.Println()- color.New(color.BgBlack, color.Bold, color.FgHiRed).Print(" π stopped early ")+ color.New(color.BgBlack, color.Bold, color.FgHiRed).Print(" π Stopped early ")fmt.Println()+ term.PrintCmds("", "log", "rewind", "tell")+ } else {+ fmt.Println()+ color.New(color.BgBlack, color.Bold, color.FgGreen).Print(" β Plan is active in the background ")+ fmt.Println()+ term.PrintCmds("", "ps", "connect", "stop")}return nildiff --git a/app/cli/stream_tui/view.go b/app/cli/stream_tui/view.goindex 901023f8..72cafc43 100644--- a/app/cli/stream_tui/view.go+++ b/app/cli/stream_tui/view.go@@ -81,17 +81,9 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {lbl := "Building plan "bgColor := color.BgGreenif outputStatic {- lbl = "Built plan "-- finishedAll := true- for _, tokens := range m.tokensByPath {- if tokens > 0 {- finishedAll = false- break- }- }-- if !finishedAll {+ if m.finished {+ lbl = "Built plan "+ } else if m.stopped || m.err != nil || m.apiErr != nil {lbl = "Build incomplete "bgColor = color.BgRed}diff --git a/app/cli/term/help.go b/app/cli/term/help.goindex 994de213..f98b8672 100644--- a/app/cli/term/help.go+++ b/app/cli/term/help.go@@ -2,6 +2,8 @@ package termimport ("fmt"+ "io"+ "os""strings""github.com/fatih/color"@@ -40,14 +42,14 @@ var CmdDesc = map[string][2]string{}func PrintCmds(prefix string, cmds ...string) {- printCmds(prefix, []color.Attribute{color.Bold, color.FgHiWhite, color.BgCyan}, cmds...)+ printCmds(os.Stderr, prefix, []color.Attribute{color.Bold, color.FgHiWhite, color.BgCyan}, cmds...)}func PrintCmdsWithColors(prefix string, colors []color.Attribute, cmds ...string) {- printCmds(prefix, colors, cmds...)+ printCmds(os.Stderr, prefix, colors, cmds...)}-func printCmds(prefix string, colors []color.Attribute, cmds ...string) {+func printCmds(w io.Writer, prefix string, colors []color.Attribute, cmds ...string) {for _, cmd := range cmds {config, ok := CmdDesc[cmd]if !ok {@@ -69,7 +71,7 @@ func printCmds(prefix string, colors []color.Attribute, cmds ...string) {}styled := color.New(colors...).Sprintf(" plandex %s ", cmd)- fmt.Printf("%s%s π %s\n", prefix, styled, desc)+ fmt.Fprintf(w, "%s%s π %s\n", prefix, styled, desc)}}@@ -83,48 +85,52 @@ func PrintCustomCmd(prefix, cmd, alias, desc string) {// PrintCustomHelp prints the custom help output for the Plandex CLIfunc PrintCustomHelp() {- color.New(color.Bold, color.BgGreen).Println(" Usage ")- color.New(color.Bold).Println(" plandex [command] [flags]")- color.New(color.Bold).Println(" pdx [command] [flags]")- fmt.Println()-- color.New(color.Bold, color.BgGreen).Println(" Help ")- color.New(color.Bold).Println(" plandex help")- color.New(color.Bold).Println(" plandex [command] --help")- fmt.Println()-- color.New(color.Bold, color.BgMagenta).Println(" Getting Started ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "new", "load", "tell", "changes", "apply")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Plans ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "new", "plans", "cd", "current", "delete-plan")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Changes ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "changes", "apply")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Context ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "load", "ls", "rm", "update", "clear")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Branches ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "branches", "checkout", "delete-branch")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" History ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "convo", "log", "rewind")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Execution ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "tell", "continue", "build")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" Active Plans ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "ps", "connect", "stop")- fmt.Println()-- color.New(color.Bold, color.BgBlue).Println(" AI Models ")- PrintCmdsWithColors(" ", []color.Attribute{color.Bold}, "models", "set-model")+ builder := &strings.Builder{}++ color.New(color.Bold, color.BgGreen).Fprintln(builder, " Usage ")+ color.New(color.Bold).Fprintln(builder, " plandex [command] [flags]")+ color.New(color.Bold).Fprintln(builder, " pdx [command] [flags]")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgGreen).Fprintln(builder, " Help ")+ color.New(color.Bold).Fprintln(builder, " plandex help")+ color.New(color.Bold).Fprintln(builder, " plandex [command] --help")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgMagenta).Fprintln(builder, " Getting Started ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "new", "load", "tell", "changes", "apply")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Plans ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "new", "plans", "cd", "current", "delete-plan")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Changes ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "changes", "apply")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Context ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "load", "ls", "rm", "update", "clear")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Branches ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "branches", "checkout", "delete-branch")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " History ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "convo", "log", "rewind")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Execution ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "tell", "continue", "build")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " Active Plans ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "ps", "connect", "stop")+ fmt.Fprintln(builder)++ color.New(color.Bold, color.BgBlue).Fprintln(builder, " AI Models ")+ printCmds(builder, " ", []color.Attribute{color.Bold}, "models", "set-model")++ fmt.Print(builder.String())}diff --git a/app/cli/term/prompt.go b/app/cli/term/prompt.goindex 1140e820..3b04c1bd 100644--- a/app/cli/term/prompt.go+++ b/app/cli/term/prompt.go@@ -2,6 +2,7 @@ package termimport ("fmt"+ "os""github.com/cqroot/prompt""github.com/cqroot/prompt/input"@@ -10,11 +11,23 @@ import ()func GetUserStringInput(msg string) (string, error) {- return prompt.New().Ask(msg).Input("")+ res, err := prompt.New().Ask(msg).Input("")++ if err.Error() == "user quit prompt" {+ os.Exit(0)+ }++ return res, err}func GetUserPasswordInput(msg string) (string, error) {- return prompt.New().Ask(msg).Input("", input.WithEchoMode(input.EchoPassword))+ res, err := prompt.New().Ask(msg).Input("", input.WithEchoMode(input.EchoPassword))++ if err.Error() == "user quit prompt" {+ os.Exit(0)+ }++ return res, err}func GetUserKeyInput() (rune, error) {diff --git a/app/cli/term/select.go b/app/cli/term/select.goindex c171b014..1c75debf 100644--- a/app/cli/term/select.go+++ b/app/cli/term/select.go@@ -2,6 +2,7 @@ package termimport ("fmt"+ "os""github.com/fatih/color""github.com/plandex-ai/survey/v2"@@ -16,6 +17,10 @@ func SelectFromList(msg string, options []string) (string, error) {}err := survey.AskOne(prompt, &selected)if err != nil {+ if err.Error() == "interrupt" {+ os.Exit(0)+ }+return "", err}