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
tell exec flow and menu fixes/refactoring
Dane Schneiderdb31caa8d4f0
diff --git a/app/cli/plan_exec/action_menu.go b/app/cli/plan_exec/action_menu.gonew file mode 100644index 00000000..5477cee7--- /dev/null+++ b/app/cli/plan_exec/action_menu.go@@ -0,0 +1,241 @@+package plan_exec++import (+ "fmt"+ "os"+ "plandex-cli/api"+ "plandex-cli/lib"+ "plandex-cli/term"+ shared "plandex-shared"+ "strings"++ "github.com/eiannone/keyboard"+ "github.com/fatih/color"+ "github.com/olekukonko/tablewriter"+)++type hotkeyOption struct {+ char string+ key keyboard.Key+ command string+ description string+ replOnly bool+ terminalOnly bool+ dropdownOnly bool+}++var allHotkeyOptions = []hotkeyOption{+ {+ char: "d",+ command: "diff ui",+ description: "Review diffs in browser UI",+ replOnly: false,+ terminalOnly: false,+ },+ {+ char: "g",+ command: "git diff format",+ description: "Review diffs in git diff format",+ replOnly: false,+ terminalOnly: false,+ },+ {+ char: "a",+ command: "apply",+ description: "Apply all pending changes",+ replOnly: false,+ terminalOnly: false,+ },+ {+ char: "r",+ command: "reject",+ description: "Reject some or all pending changes",+ replOnly: false,+ terminalOnly: false,+ },+ // {+ // char: "f",+ // command: "follow up",+ // description: "Iterate with a follow up prompt",+ // replOnly: true,+ // terminalOnly: false,+ // },+ {+ char: "q",+ key: keyboard.KeyEnter,+ command: "exit menu",+ description: "Exit menu",+ dropdownOnly: true,+ },+}++func showHotkeyMenu(diffs []string) {+ numDiffs := len(diffs)+ s := "files have"+ if numDiffs == 1 {+ s = "file has"+ }+ color.New(color.Bold, term.ColorHiGreen).Printf("π§ %d %s pending changes\n", numDiffs, s)++ // for _, diff := range diffs {+ // fmt.Printf("β’ %s\n", diff)+ // }++ fmt.Println()++ var b strings.Builder+ table := tablewriter.NewWriter(&b)+ table.SetAutoWrapText(false)+ table.SetHeaderLine(false)+ table.SetAlignment(tablewriter.ALIGN_LEFT)++ for _, opt := range allHotkeyOptions {+ if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) || opt.dropdownOnly {+ continue+ }++ table.Append([]string{+ color.New(term.ColorHiGreen, color.Bold).Sprintf("(%s)", opt.char),+ opt.command,+ opt.description,+ })+ }++ table.Render()+ fmt.Print(b.String())++ fmt.Printf("%s %s %s %s %s",+ color.New(term.ColorHiMagenta, color.Bold).Sprint("Press a hotkey,"),+ color.New(color.FgHiWhite, color.Bold).Sprintf("β"),+ color.New(term.ColorHiMagenta, color.Bold).Sprintf("to select, or"),+ color.New(color.FgHiWhite, color.Bold).Sprintf("enter"),+ color.New(term.ColorHiMagenta, color.Bold).Sprintf("to exit menu>"),+ )+}++func handleHotkey(diffs []string, params ExecParams) {+ char, key, err := term.GetUserKeyInput()+ if err != nil {+ fmt.Printf("\nError getting key: %v\n", err)+ showHotkeyMenu(diffs)+ handleHotkey(diffs, params)+ }++ if key == keyboard.KeyArrowDown {+ options := []string{}+ for _, opt := range allHotkeyOptions {+ if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) {+ continue+ }++ options = append(options, opt.description)+ }++ selected, err := term.SelectFromList(+ "Select an action",+ options,+ )+ if err != nil {+ fmt.Printf("\nError selecting action: %v\n", err)+ showHotkeyMenu(diffs)+ handleHotkey(diffs, params)+ }++ if selected != "" {+ var option hotkeyOption+ for _, opt := range allHotkeyOptions {+ if opt.description == selected {+ if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) {+ continue+ }++ option = opt+ break+ }+ }++ handleHotkeyOption(option, diffs, params)+ }+ }++ handleHotkeyOption(hotkeyOption{char: string(char), key: key}, diffs, params)+}++func handleHotkeyOption(option hotkeyOption, diffs []string, params ExecParams) {+ exitUnlessDiffs := func() {+ diffs, apiErr := getDiffs(params)+ if apiErr != nil {+ fmt.Printf("\nError getting plan diffs: %v\n", apiErr.Msg)+ os.Exit(0)+ }++ if len(diffs) == 0 {+ os.Exit(0)+ }++ showHotkeyMenu(diffs)+ handleHotkey(diffs, params)+ }++ fmt.Println()++ if option.char == "d" {+ fmt.Println()+ _, err := lib.ExecPlandexCommandWithParams([]string{"diffs", "--ui"}, lib.ExecPlandexCommandParams{+ DisableSuggestions: true,+ })+ if err != nil {+ fmt.Printf("\nError showing diffs: %v\n", err)+ }+ fmt.Println()+ } else if option.char == "g" {+ fmt.Println()+ _, err := lib.ExecPlandexCommandWithParams([]string{"diffs"}, lib.ExecPlandexCommandParams{+ DisableSuggestions: true,+ })+ if err != nil {+ fmt.Printf("\nError showing diffs: %v\n", err)+ }+ fmt.Println()+ } else if option.char == "a" {+ fmt.Println()+ _, err := lib.ExecPlandexCommand([]string{"apply"})+ if err != nil {+ fmt.Printf("\nError applying changes: %v\n", err)+ }+ fmt.Println()+ exitUnlessDiffs()+ } else if option.char == "r" {+ fmt.Println()+ _, err := lib.ExecPlandexCommand([]string{"reject"})+ if err != nil {+ fmt.Printf("\nError rejecting changes: %v\n", err)+ }+ fmt.Println()+ exitUnlessDiffs()+ } else if option.char == "q" || option.key == keyboard.KeyEnter {+ os.Exit(0)+ // } else if option.char == "f" {+ // if term.IsRepl {+ // color.New(color.Bold).Println("Write a prompt π")+ // os.Exit(0)+ // } else {+ // term.PrintCmds("", "tell", "chat")+ // os.Exit(0)+ // }+ } else {+ fmt.Println("\nInvalid hotkey")+ }++ showHotkeyMenu(diffs)+ handleHotkey(diffs, params)+}++func getDiffs(params ExecParams) ([]string, *shared.ApiError) {+ currentPlan, apiErr := api.Client.GetCurrentPlanState(params.CurrentPlanId, params.CurrentBranch)+ if apiErr != nil {+ return nil, apiErr+ }++ return currentPlan.PlanResult.SortedPaths, nil+}diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.goindex f44d4c80..07d68d8c 100644--- a/app/cli/plan_exec/tell.go+++ b/app/cli/plan_exec/tell.go@@ -7,83 +7,24 @@ import ("plandex-cli/api""plandex-cli/auth""plandex-cli/fs"- "plandex-cli/lib""plandex-cli/stream"streamtui "plandex-cli/stream_tui""plandex-cli/term"-- "strings"+ "plandex-cli/types"shared "plandex-shared"- "github.com/eiannone/keyboard"+ "github.com/davecgh/go-spew/spew""github.com/fatih/color"- "github.com/olekukonko/tablewriter")-type hotkeyOption struct {- char string- key keyboard.Key- command string- description string- replOnly bool- terminalOnly bool- dropdownOnly bool-}--var allHotkeyOptions = []hotkeyOption{- {- char: "d",- command: "diff ui",- description: "Review diffs in browser UI",- replOnly: false,- terminalOnly: false,- },- {- char: "g",- command: "git diff format",- description: "Review diffs in git diff format",- replOnly: false,- terminalOnly: false,- },- {- char: "a",- command: "apply",- description: "Apply all pending changes",- replOnly: false,- terminalOnly: false,- },- {- char: "r",- command: "reject",- description: "Reject some or all pending changes",- replOnly: false,- terminalOnly: false,- },- // {- // char: "f",- // command: "follow up",- // description: "Iterate with a follow up prompt",- // replOnly: true,- // terminalOnly: false,- // },- {- char: "q",- key: keyboard.KeyEnter,- command: "continue",- description: "Continue",- dropdownOnly: true,- },-}-func TellPlan(params ExecParams,prompt string,- flags TellFlags,+ flags types.TellFlags,) {- // showHotkeyMenu([]string{"a", "r"})- // handleHotkey([]string{"a", "r"}, params)- // return+ log.Println("plan_exec.TellPlan")+ log.Println("flags", spew.Sdump(flags))tellBg := flags.TellBgtellStop := flags.TellStop@@ -93,6 +34,8 @@ func TellPlan(isChatOnly := flags.IsChatOnlyautoContext := flags.AutoContextexecEnabled := flags.ExecEnabled+ autoApply := flags.AutoApply+ isApplyDebug := flags.IsApplyDebugdone := make(chan struct{})@@ -246,6 +189,8 @@ func TellPlan(if !term.IsRepl {term.PrintCmds("", "tell", "convo", "summary", "log")}+ } else if autoApply || isDebugCmd || isApplyDebug {+ // do nothing, allow auto apply to run} else {diffs, apiErr := getDiffs(params)numDiffs := len(diffs)@@ -265,7 +210,7 @@ func TellPlan(} else {term.PrintCmds("", "continue", "log")}- } else if !isDebugCmd && hasDiffs {+ } else if hasDiffs {// term.PrintCmds("", "diff", "diff --ui", "apply", "reject", "log")showHotkeyMenu(diffs)handleHotkey(diffs, params)@@ -293,174 +238,3 @@ func TellPlan(<-done}}--func showHotkeyMenu(diffs []string) {- numDiffs := len(diffs)- s := "files have"- if numDiffs == 1 {- s = "file has"- }- color.New(color.Bold, term.ColorHiGreen).Printf("π§ %d %s pending changes\n", numDiffs, s)-- // for _, diff := range diffs {- // fmt.Printf("β’ %s\n", diff)- // }-- fmt.Println()-- var b strings.Builder- table := tablewriter.NewWriter(&b)- table.SetAutoWrapText(false)- table.SetHeaderLine(false)- table.SetAlignment(tablewriter.ALIGN_LEFT)-- for _, opt := range allHotkeyOptions {- if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) || opt.dropdownOnly {- continue- }-- table.Append([]string{- color.New(term.ColorHiGreen, color.Bold).Sprintf("(%s)", opt.char),- opt.command,- opt.description,- })- }-- table.Render()- fmt.Print(b.String())-- fmt.Printf("%s %s %s %s %s",- color.New(term.ColorHiMagenta, color.Bold).Sprint("Press a hotkey,"),- color.New(color.FgHiWhite, color.Bold).Sprintf("β"),- color.New(term.ColorHiMagenta, color.Bold).Sprintf("to select,"),- color.New(color.FgHiWhite, color.Bold).Sprintf("enter"),- color.New(term.ColorHiMagenta, color.Bold).Sprintf("to continue>"),- )-}--func handleHotkey(diffs []string, params ExecParams) {- char, key, err := term.GetUserKeyInput()- if err != nil {- fmt.Printf("\nError getting key: %v\n", err)- showHotkeyMenu(diffs)- handleHotkey(diffs, params)- }-- if key == keyboard.KeyArrowDown {- options := []string{}- for _, opt := range allHotkeyOptions {- if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) {- continue- }-- options = append(options, opt.description)- }-- selected, err := term.SelectFromList(- "Select an action",- options,- )- if err != nil {- fmt.Printf("\nError selecting action: %v\n", err)- showHotkeyMenu(diffs)- handleHotkey(diffs, params)- }-- if selected != "" {- var option hotkeyOption- for _, opt := range allHotkeyOptions {- if opt.description == selected {- if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) {- continue- }-- option = opt- break- }- }-- handleHotkeyOption(option, diffs, params)- }- }-- handleHotkeyOption(hotkeyOption{char: string(char)}, diffs, params)-}--func handleHotkeyOption(option hotkeyOption, diffs []string, params ExecParams) {- exitUnlessDiffs := func() {- diffs, apiErr := getDiffs(params)- if apiErr != nil {- fmt.Printf("\nError getting plan diffs: %v\n", apiErr.Msg)- os.Exit(0)- }-- if len(diffs) == 0 {- os.Exit(0)- }-- showHotkeyMenu(diffs)- handleHotkey(diffs, params)- }-- fmt.Println()-- if option.char == "d" {- fmt.Println()- _, err := lib.ExecPlandexCommandWithParams([]string{"diffs", "--ui"}, lib.ExecPlandexCommandParams{- DisableSuggestions: true,- })- if err != nil {- fmt.Printf("\nError showing diffs: %v\n", err)- }- fmt.Println()- } else if option.char == "g" {- fmt.Println()- _, err := lib.ExecPlandexCommandWithParams([]string{"diffs"}, lib.ExecPlandexCommandParams{- DisableSuggestions: true,- })- if err != nil {- fmt.Printf("\nError showing diffs: %v\n", err)- }- fmt.Println()- } else if option.char == "a" {- fmt.Println()- _, err := lib.ExecPlandexCommand([]string{"apply"})- if err != nil {- fmt.Printf("\nError applying changes: %v\n", err)- }- fmt.Println()- exitUnlessDiffs()- } else if option.char == "r" {- fmt.Println()- _, err := lib.ExecPlandexCommand([]string{"reject"})- if err != nil {- fmt.Printf("\nError rejecting changes: %v\n", err)- }- fmt.Println()- exitUnlessDiffs()- } else if option.char == "q" || option.key == keyboard.KeyEnter {- os.Exit(0)- // } else if option.char == "f" {- // if term.IsRepl {- // color.New(color.Bold).Println("Write a prompt π")- // os.Exit(0)- // } else {- // term.PrintCmds("", "tell", "chat")- // os.Exit(0)- // }- } else {- fmt.Println("\nInvalid command")- }-- showHotkeyMenu(diffs)- handleHotkey(diffs, params)-}--func getDiffs(params ExecParams) ([]string, *shared.ApiError) {- currentPlan, apiErr := api.Client.GetCurrentPlanState(params.CurrentPlanId, params.CurrentBranch)- if apiErr != nil {- return nil, apiErr- }-- return currentPlan.PlanResult.SortedPaths, nil-}diff --git a/app/cli/types/apply.go b/app/cli/types/apply.goindex bda2622f..19c8f77d 100644--- a/app/cli/types/apply.go+++ b/app/cli/types/apply.go@@ -4,6 +4,15 @@ import ("os")+type ApplyFlags struct {+ AutoConfirm bool+ AutoCommit bool+ NoCommit bool+ AutoExec bool+ NoExec bool+ AutoDebug int+}+type ApplyRollbackOption stringconst (diff --git a/app/cli/types/exec.go b/app/cli/types/exec.gonew file mode 100644index 00000000..92e495d5--- /dev/null+++ b/app/cli/types/exec.go@@ -0,0 +1,19 @@+package types++type TellFlags struct {+ TellBg bool+ TellStop bool+ TellNoBuild bool+ IsUserContinue bool+ IsUserDebug bool+ IsApplyDebug bool+ IsChatOnly bool+ AutoContext bool+ ContinuedAfterAction bool+ ExecEnabled bool+ AutoApply bool+}+type BuildFlags struct {+ BuildBg bool+ AutoApply bool+}