Skip to content

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

feat: improve apply script execution with full auto mode support and better debugging

Dane Schneider867ed49f23bb
diff --git a/app/cli/plan_exec/action_menu.go b/app/cli/plan_exec/action_menu.go
index b5a5bbf7..318201f5 100644
--- a/app/cli/plan_exec/action_menu.go
+++ b/app/cli/plan_exec/action_menu.go
@@ -15,13 +15,14 @@ import (
)
type hotkeyOption struct {
- char string
- key keyboard.Key
- command string
- description string
- replOnly bool
- terminalOnly bool
- dropdownOnly bool
+ char string
+ key keyboard.Key
+ command string
+ description string
+ replOnly bool
+ terminalOnly bool
+ dropdownOnly bool
+ applyScriptOnly bool
}
var allHotkeyOptions = []hotkeyOption{
@@ -39,6 +40,14 @@ var allHotkeyOptions = []hotkeyOption{
replOnly: false,
terminalOnly: false,
},
+ {
+ char: "r",
+ command: "reject",
+ description: "Reject some or all pending changes",
+ replOnly: false,
+ terminalOnly: false,
+ },
+
{
char: "a",
command: "apply",
@@ -46,20 +55,16 @@ var allHotkeyOptions = []hotkeyOption{
replOnly: false,
terminalOnly: false,
},
+
{
- char: "r",
- command: "reject",
- description: "Reject some or all pending changes",
- replOnly: false,
- terminalOnly: false,
+ char: "f",
+ command: "full auto",
+ description: "Apply and debug in full auto mode",
+ replOnly: true,
+ terminalOnly: false,
+ applyScriptOnly: true,
},
- // {
- // char: "f",
- // command: "follow up",
- // description: "Iterate with a follow up prompt",
- // replOnly: true,
- // terminalOnly: false,
- // },
+
{
char: "q",
key: keyboard.KeyEnter,
@@ -70,6 +75,14 @@ var allHotkeyOptions = []hotkeyOption{
}
func showHotkeyMenu(diffs []string) {
+ hasApplyScript := false
+ for _, diff := range diffs {
+ if diff == "_apply.sh" {
+ hasApplyScript = true
+ break
+ }
+ }
+
numDiffs := len(diffs)
s := "files have"
if numDiffs == 1 {
@@ -78,11 +91,19 @@ func showHotkeyMenu(diffs []string) {
color.New(color.Bold, term.ColorHiGreen).Printf("🧐 %d %s pending changes\n", numDiffs, s)
for _, diff := range diffs {
+ if diff == "_apply.sh" {
+ continue
+ }
+
fmt.Printf("β€’ πŸ“„ %s\n", diff)
}
-
fmt.Println()
+ if hasApplyScript {
+ color.New(color.Bold, term.ColorHiYellow).Println("πŸš€ Commands pending")
+ fmt.Println()
+ }
+
var b strings.Builder
table := tablewriter.NewWriter(&b)
table.SetAutoWrapText(false)
@@ -90,12 +111,21 @@ func showHotkeyMenu(diffs []string) {
table.SetAlignment(tablewriter.ALIGN_LEFT)
for _, opt := range allHotkeyOptions {
- if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) || opt.dropdownOnly {
+ if (opt.terminalOnly && term.IsRepl) || (opt.replOnly && !term.IsRepl) || opt.dropdownOnly || (opt.applyScriptOnly && !hasApplyScript) {
continue
}
+ c := color.New(term.ColorHiCyan, color.Bold)
+ if opt.command == "apply" {
+ c = color.New(term.ColorHiGreen, color.Bold)
+ } else if opt.command == "reject" {
+ c = color.New(term.ColorHiRed, color.Bold)
+ } else if opt.command == "full auto" {
+ c = color.New(term.ColorHiYellow, color.Bold)
+ }
+
table.Append([]string{
- color.New(term.ColorHiGreen, color.Bold).Sprintf("(%s)", opt.char),
+ c.Sprintf("(%s)", opt.char),
opt.command,
opt.description,
})
@@ -213,6 +243,14 @@ func handleHotkeyOption(option hotkeyOption, diffs []string, params ExecParams)
}
fmt.Println()
exitUnlessDiffs()
+ } else if option.char == "f" {
+ fmt.Println()
+ _, err := lib.ExecPlandexCommand([]string{"apply", "--auto"})
+ if err != nil {
+ fmt.Printf("\nError applying changes: %v\n", err)
+ }
+ fmt.Println()
+ exitUnlessDiffs()
} else if option.char == "q" || option.key == keyboard.KeyEnter {
os.Exit(0)
// } else if option.char == "f" {
diff --git a/app/cli/plan_exec/apply_exec.go b/app/cli/plan_exec/apply_exec.go
index d0df34ae..a3cfb046 100644
--- a/app/cli/plan_exec/apply_exec.go
+++ b/app/cli/plan_exec/apply_exec.go
@@ -3,6 +3,7 @@ package plan_exec
import (
"fmt"
"log"
+ "plandex-cli/api"
"plandex-cli/auth"
"plandex-cli/lib"
"plandex-cli/term"
@@ -25,6 +26,7 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
var onExecFail types.OnApplyExecFailFn
onExecFail = func(status int, output string, attempt int, toRollback *types.ApplyRollbackPlan, onErr types.OnErrFn, onSuccess func()) {
var proceed bool
+ resetAttempts := false
if applyFlags.AutoDebug > 0 {
if attempt >= applyFlags.AutoDebug {
@@ -39,13 +41,71 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
}
if !proceed {
- confirm, err := term.ConfirmYesNo("Auto-debug?")
+ const (
+ DebugAndRetry = "Debug and retry once"
+ DebugInFullAutoMode = "Debug in full auto mode"
+ RollbackChangesAndExit = "Rollback changes and exit"
+ ApplyChangesAndExit = "Apply changes and exit"
+ )
+ opts := []string{
+ DebugAndRetry,
+ DebugInFullAutoMode,
+ RollbackChangesAndExit,
+ ApplyChangesAndExit,
+ }
+ selection, err := term.SelectFromList("What do you want to do?", opts)
if err != nil {
term.OutputErrorAndExit("failed to get confirmation user input: %s", err)
}
- proceed = confirm
+ switch selection {
+ case DebugAndRetry:
+ proceed = true
+ case DebugInFullAutoMode:
+ proceed = true
+ resetAttempts = true
+
+ term.StartSpinner("")
+ config, apiErr := api.Client.GetPlanConfig(lib.CurrentPlanId)
+
+ if apiErr != nil {
+ term.OutputErrorAndExit("failed to get plan config: %s", apiErr)
+ }
+
+ config.SetAutoMode(shared.AutoModeFull)
+ apiErr = api.Client.UpdatePlanConfig(lib.CurrentPlanId, shared.UpdatePlanConfigRequest{
+ Config: config,
+ })
+
+ if apiErr != nil {
+ term.OutputErrorAndExit("failed to update plan config: %s", apiErr)
+ }
+
+ applyFlags.AutoCommit = true
+ applyFlags.AutoConfirm = true
+ applyFlags.AutoExec = true
+ applyFlags.AutoDebug = config.AutoDebugTries
+
+ tellFlags.AutoApply = true
+ tellFlags.AutoContext = true
+ tellFlags.ExecEnabled = true
+ tellFlags.SmartContext = true
+
+ term.StopSpinner()
+ fmt.Println()
+ fmt.Println("βœ… Full auto mode enabled")
+ fmt.Println()
+
+ case RollbackChangesAndExit:
+ if toRollback != nil {
+ lib.Rollback(toRollback, true)
+ }
+ term.OutputErrorAndExit("Rolling back changes and exiting")
+ case ApplyChangesAndExit:
+ onSuccess()
+ return
+ }
}
if proceed {
@@ -85,6 +145,10 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
log.Printf("Applying plan after tell")
+ if resetAttempts {
+ attempt = 0
+ }
+
lib.MustApplyPlanAttempt(lib.ApplyPlanParams{
PlanId: lib.CurrentPlanId,
Branch: lib.CurrentBranch,
@@ -93,18 +157,6 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
OnExecFail: onExecFail,
ExecCommand: execCommand,
}, attempt+1)
- } else {
- res, err := term.SelectFromList("Still apply file changes or roll back?", []string{string(types.ApplyRollbackOptionKeep), string(types.ApplyRollbackOptionRollback)})
-
- if err != nil {
- onErr("failed to get rollback confirmation user input: %s", err)
- }
-
- if res == string(types.ApplyRollbackOptionRollback) {
- lib.Rollback(toRollback, true)
- } else {
- onSuccess()
- }
}
}