Skip to content

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

prompt for context updates/inline builds where needed (apply + changes) as well as some refactoring to enable this

Dane Schneider3daa7742bcef
diff --git a/app/cli/changes_tui/run.go b/app/cli/changes_tui/run.go
index 6a2de4fa..e12b88d4 100644
--- a/app/cli/changes_tui/run.go
+++ b/app/cli/changes_tui/run.go
@@ -23,7 +23,7 @@ func StartChangesUI() error {
}
if m.(changesUIModel).shouldApplyAll {
- err := lib.ApplyPlanWithOutput(lib.CurrentPlanId, lib.CurrentBranch, false)
+ err := lib.ApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, false)
if err != nil {
return fmt.Errorf("error applying plan: %v", err)
diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.go
index f75d2d6e..2865f1ec 100644
--- a/app/cli/cmd/apply.go
+++ b/app/cli/cmd/apply.go
@@ -32,7 +32,7 @@ func apply(cmd *cobra.Command, args []string) {
return
}
- err := lib.ApplyPlanWithOutput(lib.CurrentPlanId, lib.CurrentBranch, autoConfirm)
+ err := lib.ApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, autoConfirm)
if err != nil {
fmt.Println("Error applying plan:", err)
diff --git a/app/cli/cmd/build.go b/app/cli/cmd/build.go
index 85c66a5e..3ec7fd2b 100644
--- a/app/cli/cmd/build.go
+++ b/app/cli/cmd/build.go
@@ -8,6 +8,7 @@ import (
"plandex/plan_exec"
"plandex/term"
+ "github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
)
@@ -42,9 +43,11 @@ func build(cmd *cobra.Command, args []string) {
}
didBuild, err := plan_exec.Build(plan_exec.ExecParams{
- CurrentPlanId: lib.CurrentPlanId,
- CurrentBranch: lib.CurrentBranch,
- CheckOutdatedContext: func() { lib.MustCheckOutdatedContext(false) },
+ CurrentPlanId: lib.CurrentPlanId,
+ CurrentBranch: lib.CurrentBranch,
+ CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
+ return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
+ },
}, buildBg)
if err != nil {
diff --git a/app/cli/cmd/changes.go b/app/cli/cmd/changes.go
index 88a6d670..e78f5ae8 100644
--- a/app/cli/cmd/changes.go
+++ b/app/cli/cmd/changes.go
@@ -3,10 +3,14 @@ package cmd
import (
"fmt"
"os"
+ "plandex/api"
"plandex/auth"
"plandex/changes_tui"
"plandex/lib"
+ "plandex/plan_exec"
+ "plandex/term"
+ "github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
)
@@ -25,6 +29,78 @@ func changes(cmd *cobra.Command, args []string) {
auth.MustResolveAuthWithOrg()
lib.MustResolveProject()
+ term.StartSpinner("πŸ”¬ Checking plan state...")
+
+ currentPlanState, apiErr := api.Client.GetCurrentPlanState(lib.CurrentPlanId, lib.CurrentBranch)
+
+ if apiErr != nil {
+ term.StopSpinner()
+ fmt.Fprintf(os.Stderr, "Error getting current plan state: %s\n", apiErr.Msg)
+ return
+ }
+
+ if currentPlanState.HasPendingBuilds() {
+ plansRunningRes, apiErr := api.Client.ListPlansRunning([]string{lib.CurrentProjectId}, false)
+
+ if apiErr != nil {
+ // return fmt.Errorf("error getting running plans: %s", apiErr.Msg)
+ term.StopSpinner()
+ fmt.Fprintf(os.Stderr, "Error getting running plans: %s\n", apiErr.Msg)
+ }
+
+ viewIncomplete := false
+
+ for _, b := range plansRunningRes.Branches {
+ if b.PlanId == lib.CurrentPlanId && b.Name == lib.CurrentBranch {
+ fmt.Println("This plan is currently active.")
+
+ res, err := term.ConfirmYesNo("View potentially incomplete changes anyway?")
+
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error getting confirmation user input: %s\n", err)
+ return
+ }
+
+ if res {
+ viewIncomplete = true
+ break
+ } else {
+ fmt.Println()
+ term.PrintCmds("", "ps", "connect")
+ return
+ }
+ }
+ }
+
+ term.StopSpinner()
+
+ if !viewIncomplete {
+ fmt.Println("This plan has unbuilt changes. Building now.")
+
+ didBuild, err := plan_exec.Build(plan_exec.ExecParams{
+ CurrentPlanId: lib.CurrentPlanId,
+ CurrentBranch: lib.CurrentBranch,
+ CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
+ return lib.MustCheckOutdatedContext(cancelOpt, true, maybeContexts)
+ },
+ }, false)
+
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error building plan: %v\n", err)
+ return
+ }
+
+ if !didBuild {
+ fmt.Println("Build canceled")
+ fmt.Println()
+ term.PrintCmds("", "build", "log", "rewind")
+ return
+ }
+ }
+ }
+
+ term.StopSpinner()
+
err := changes_tui.StartChangesUI()
if err != nil {
diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.go
index 9b6712fa..812b7291 100644
--- a/app/cli/cmd/continue.go
+++ b/app/cli/cmd/continue.go
@@ -8,6 +8,7 @@ import (
"plandex/plan_exec"
"plandex/term"
+ "github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
)
@@ -41,8 +42,10 @@ func doContinue(cmd *cobra.Command, args []string) {
}
plan_exec.TellPlan(plan_exec.ExecParams{
- CurrentPlanId: lib.CurrentPlanId,
- CurrentBranch: lib.CurrentBranch,
- CheckOutdatedContext: func() { lib.MustCheckOutdatedContext(false) },
+ CurrentPlanId: lib.CurrentPlanId,
+ CurrentBranch: lib.CurrentBranch,
+ CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
+ return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
+ },
}, "", tellBg, tellStop, tellNoBuild, true)
}
diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.go
index 2831138e..09e560b5 100644
--- a/app/cli/cmd/tell.go
+++ b/app/cli/cmd/tell.go
@@ -10,6 +10,7 @@ import (
"plandex/term"
"strings"
+ "github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
)
@@ -76,9 +77,11 @@ func doTell(cmd *cobra.Command, args []string) {
}
plan_exec.TellPlan(plan_exec.ExecParams{
- CurrentPlanId: lib.CurrentPlanId,
- CurrentBranch: lib.CurrentBranch,
- CheckOutdatedContext: func() { lib.MustCheckOutdatedContext(false) },
+ CurrentPlanId: lib.CurrentPlanId,
+ CurrentBranch: lib.CurrentBranch,
+ CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
+ return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
+ },
}, prompt, tellBg, tellStop, tellNoBuild, false)
}
diff --git a/app/cli/cmd/update.go b/app/cli/cmd/update.go
index 9f3e9f79..93918be0 100644
--- a/app/cli/cmd/update.go
+++ b/app/cli/cmd/update.go
@@ -24,5 +24,5 @@ func update(cmd *cobra.Command, args []string) {
auth.MustResolveAuthWithOrg()
lib.MustResolveProject()
- lib.MustUpdateContext()
+ lib.MustUpdateContext(nil)
}
diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.go
index 3aeb62b6..d4de1a6c 100644
--- a/app/cli/lib/apply.go
+++ b/app/cli/lib/apply.go
@@ -1,227 +1,81 @@
package lib
import (
- "crypto/sha256"
- "encoding/hex"
"fmt"
"os"
"path/filepath"
"plandex/api"
"plandex/fs"
"plandex/term"
- "plandex/types"
"github.com/fatih/color"
- "github.com/olekukonko/tablewriter"
- "github.com/plandex/plandex/shared"
)
-func ApplyPlanWithOutput(planId, branch string, autoConfirm bool) error {
+func ApplyPlan(planId, branch string, autoConfirm bool) error {
+ term.StartSpinner("πŸ”¬ Checking plan state...")
+
currentPlanState, apiErr := api.Client.GetCurrentPlanState(planId, branch)
if apiErr != nil {
+ term.StopSpinner()
return fmt.Errorf("error getting current plan state: %s", apiErr.Msg)
}
if currentPlanState.HasPendingBuilds() {
+ plansRunningRes, apiErr := api.Client.ListPlansRunning([]string{CurrentProjectId}, false)
- }
-
- currentPlanFiles := currentPlanState.CurrentPlanFiles
- planResByPath := currentPlanState.PlanResult.FileResultsByPath
-
- if len(currentPlanFiles.Files) == 0 {
- fmt.Println("πŸ€·β€β™‚οΈ No changes to apply")
- return nil
- }
-
- aborted := false
-
- // check if any files have been modified since the plan result was generated
- pathsRemoved := []string{}
- pathsOutdated := []string{}
- pathsUnmodified := []string{}
- pathsNew := []string{}
- pathsRemovedOrOutdatedSet := map[string]bool{}
- outdatedCanMergeSet := map[string]bool{}
-
- canMergeAllOutdated := true
- var err error
-
- for path := range currentPlanFiles.Files {
- context := currentPlanState.ContextsByPath[path]
- var contextSha string
- if context != nil {
- contextSha = currentPlanState.ContextsByPath[path].Sha
+ if apiErr != nil {
+ term.StopSpinner()
+ return fmt.Errorf("error getting running plans: %s", apiErr.Msg)
}
- if contextSha == "" {
- // the path wasn't in context
- pathsNew = append(pathsNew, path)
- continue
+ for _, b := range plansRunningRes.Branches {
+ if b.PlanId == planId && b.Name == branch {
+ fmt.Println("This plan is currently active. Please wait for it to finish before applying.")
+ fmt.Println()
+ term.PrintCmds("", "ps", "connect")
+ return nil
+ }
}
- // Compute destination path
- dstPath := filepath.Join(fs.ProjectRoot, path)
+ term.StopSpinner()
- // Check if the file has been removed
- _, err := os.Stat(dstPath)
-
- if os.IsNotExist(err) {
- pathsRemoved = append(pathsRemoved, path)
- pathsRemovedOrOutdatedSet[path] = true
- } else if err != nil {
- return fmt.Errorf("failed to check existence of %s: %w", dstPath, err)
- }
+ fmt.Println("This plan has changes that need to be built before applying")
+ fmt.Println()
- // Read the file
- bytes, err := os.ReadFile(dstPath)
+ shouldBuild, err := term.ConfirmYesNo("Build changes now?")
if err != nil {
- return fmt.Errorf("failed to read %s: %w", dstPath, err)
- }
-
- // Get the sha of the file
- hash := sha256.Sum256(bytes)
- fileSha := hex.EncodeToString(hash[:])
-
- if fileSha == contextSha {
- pathsUnmodified = append(pathsUnmodified, path)
- } else {
- pathsOutdated = append(pathsOutdated, path)
- pathsRemovedOrOutdatedSet[path] = true
-
- planRes := planResByPath[path]
-
- updated := string(bytes)
- allSucceeded := true
- for _, res := range planRes {
- var succeeded bool
- updated, succeeded = shared.ApplyReplacements(updated, res.Replacements, false)
- if !succeeded {
- allSucceeded = false
- canMergeAllOutdated = false
- break
- }
- }
- outdatedCanMergeSet[path] = allSucceeded
- }
- }
-
- table := tablewriter.NewWriter(os.Stdout)
- table.SetHeader([]string{"Path", "Status"})
- table.SetAutoWrapText(false)
-
- numConflicts := len(pathsRemoved) + len(pathsOutdated)
- hasConflicts := numConflicts > 0
-
- if hasConflicts {
- suffix := ""
- verb := "has"
- if numConflicts > 1 {
- suffix = "s"
- verb = "have"
+ return fmt.Errorf("failed to get confirmation user input: %s", err)
}
- color.New(color.Bold).Printf("⚠️ %d file%s in context %s been modified since the plan was generated\n\n", numConflicts, suffix, verb)
-
- for _, path := range pathsRemoved {
- table.Rich([]string{path, "πŸ”΄ Removed"}, []tablewriter.Colors{
- {tablewriter.FgHiRedColor, tablewriter.Bold},
- {tablewriter.FgHiWhiteColor},
- })
+ if !shouldBuild {
+ fmt.Println("Apply plan canceled")
+ os.Exit(0)
}
- for _, path := range pathsOutdated {
- s := "🟑 Modified"
- if outdatedCanMergeSet[path] {
- s += " " + color.New(color.BgGreen).Sprint(" Can still apply changes ")
- } else {
- s += " " + color.New(color.BgRed).Sprint(" Can't apply changes ")
- }
-
- table.Rich([]string{path, s}, []tablewriter.Colors{
- {tablewriter.FgHiYellowColor, tablewriter.Bold},
- {tablewriter.FgHiWhiteColor},
- })
- }
- } else {
- numUnmodified := len(pathsUnmodified) + len(pathsNew)
- suffix := ""
+ _, err = buildPlanInlineFn(nil)
- if numUnmodified > 1 {
- suffix = "s"
+ if err != nil {
+ return fmt.Errorf("failed to build plan: %w", err)
}
-
- color.New(color.Bold).Printf("⚑️ %d file%s will be updated\n\n", numUnmodified, suffix)
- }
-
- for _, path := range pathsUnmodified {
- table.Rich([]string{path, "🟒 Ready for update"}, []tablewriter.Colors{
- {tablewriter.FgHiGreenColor, tablewriter.Bold},
- {tablewriter.FgHiWhiteColor},
- })
- }
-
- for _, path := range pathsNew {
- table.Rich([]string{path, "πŸ”΅ New file"}, []tablewriter.Colors{
- {tablewriter.FgHiCyanColor, tablewriter.Bold},
- {tablewriter.FgHiWhiteColor},
- })
}
- table.Render()
-
- var conflictStrategy string
-
- if hasConflicts {
- fmt.Println()
-
- if conflictStrategy == "" {
- options := []string{
- types.PlanOutdatedStrategyOverwrite,
- }
-
- if len(currentPlanFiles.Files) > (len(pathsRemoved) + len(pathsOutdated)) {
- options = append(options, types.PlanOutdatedStrategyApplyUnmodified)
- }
-
- if canMergeAllOutdated {
- options = append(options, types.PlanOutdatedStrategyApplyNoConflicts)
- }
-
- options = append(options,
- // types.PlanOutdatedStrategyRebuild, // TODO: implement rebuild
- types.PlanOutdatedStrategyCancel,
- )
-
- choice, err := term.SelectFromList("πŸ€” How do you want to handle it?", options)
-
- if err != nil {
- return fmt.Errorf("failed to get user input: %w", err)
- }
+ anyOutdated, didUpdate, _ := MustCheckOutdatedContext(false, true, nil)
- conflictStrategy = choice
- }
+ if anyOutdated && !didUpdate {
+ term.StopSpinner()
+ fmt.Println("Apply plan canceled")
+ os.Exit(0)
}
- switch conflictStrategy {
- case types.PlanOutdatedStrategyOverwrite:
- fmt.Println("⚑️ Overwriting modifications")
-
- case types.PlanOutdatedStrategyApplyUnmodified:
- fmt.Println("⚑️ Applying only new and unmodified files")
-
- case types.PlanOutdatedStrategyApplyNoConflicts:
- // nothing to do
+ term.StopSpinner()
- case types.PlanOutdatedStrategyRebuild:
- fmt.Println("⚑️ Rebuilding the plan with updated context")
- // TODO: rebuild the plan
- return nil
+ currentPlanFiles := currentPlanState.CurrentPlanFiles
- case types.PlanOutdatedStrategyCancel:
- aborted = true
+ if len(currentPlanFiles.Files) == 0 {
+ term.StopSpinner()
+ fmt.Println("πŸ€·β€β™‚οΈ No changes to apply")
return nil
}
@@ -230,6 +84,7 @@ func ApplyPlanWithOutput(planId, branch string, autoConfirm bool) error {
hasUncommittedChanges := false
if isRepo {
// Check if there are any uncommitted changes
+ var err error
hasUncommittedChanges, err = CheckUncommittedChanges()
if err != nil {
@@ -237,22 +92,14 @@ func ApplyPlanWithOutput(planId, branch string, autoConfirm bool) error {
}
}
- toApply := map[string]string{}
- for path, content := range currentPlanFiles.Files {
- outdated := pathsRemovedOrOutdatedSet[path]
- if outdated {
- if conflictStrategy == types.PlanOutdatedStrategyOverwrite || conflictStrategy == types.PlanOutdatedStrategyApplyNoConflicts {
- toApply[path] = content
- }
- } else {
- toApply[path] = content
- }
- }
+ toApply := currentPlanFiles.Files
+
+ var aborted bool
if len(toApply) == 0 {
fmt.Println("πŸ€·β€β™‚οΈ No changes to apply")
} else {
- if !autoConfirm && !hasConflicts {
+ if !autoConfirm {
fmt.Println()
numToApply := len(toApply)
suffix := ""
@@ -321,7 +168,7 @@ func ApplyPlanWithOutput(planId, branch string, autoConfirm bool) error {
if isRepo {
// Commit the changes
- err = GitAddAndCommit(fs.ProjectRoot, color.New(color.BgBlue, color.FgHiWhite, color.Bold).Sprintln(" πŸ€– Plandex ")+currentPlanState.PendingChangesSummary(), true)
+ err := GitAddAndCommit(fs.ProjectRoot, color.New(color.BgBlue, color.FgHiWhite, color.Bold).Sprintln(" πŸ€– Plandex ")+currentPlanState.PendingChangesSummary(), true)
if err != nil {
aborted = true
return fmt.Errorf("failed to commit changes: %w", err)
diff --git a/app/cli/lib/build.go b/app/cli/lib/build.go
index 36ae5e53..975d8291 100644
--- a/app/cli/lib/build.go
+++ b/app/cli/lib/build.go
@@ -1,7 +1,9 @@
package lib
-var buildPlanInlineFn func() (bool, error)
+import "github.com/plandex/plandex/shared"
-func SetBuildPlanInlineFn(fn func() (bool, error)) {
+var buildPlanInlineFn func(maybeContexts []*shared.Context) (bool, error)
+
+func SetBuildPlanInlineFn(fn func(maybeContexts []*shared.Context) (bool, error)) {
buildPlanInlineFn = fn
}
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index 898bee84..4edb5f0f 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -258,7 +258,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
if hasConflicts {
term.StartSpinner("πŸ—οΈ Starting build...")
- _, err := buildPlanInlineFn()
+ _, err := buildPlanInlineFn(nil)
if err != nil {
onErr(fmt.Errorf("failed to build plan: %v", err))
diff --git a/app/cli/lib/context_update.go b/app/cli/lib/context_update.go
index 61ec5984..08204a3c 100644
--- a/app/cli/lib/context_update.go
+++ b/app/cli/lib/context_update.go
@@ -18,26 +18,24 @@ import (
"github.com/plandex/plandex/shared"
)
-func MustCheckOutdatedContext(quiet bool) {
+func MustCheckOutdatedContext(cancelOpt, quiet bool, maybeContexts []*shared.Context) (contextOutdated, updated, canceled bool) {
if !quiet {
term.StartSpinner("πŸ”¬ Checking context...")
}
- outdatedRes, err := CheckOutdatedContext()
+ outdatedRes, err := CheckOutdatedContext(maybeContexts)
if err != nil {
term.StopSpinner()
panic(fmt.Errorf("failed to check outdated context: %s", err))
}
- if !quiet {
- term.StopSpinner()
- }
+ term.StopSpinner()
if len(outdatedRes.UpdatedContexts) == 0 {
if !quiet {
fmt.Println("βœ… Context is up to date")
}
- return
+ return false, false, false
}
types := []string{}
if outdatedRes.NumFiles > 0 {
@@ -89,26 +87,29 @@ func MustCheckOutdatedContext(quiet bool) {
fmt.Println()
- confirmed, canceled, err := term.ConfirmYesNoCancel("Update context now?")
+ var confirmed bool
+
+ if cancelOpt {
+ confirmed, canceled, err = term.ConfirmYesNoCancel("Update context now?")
+ } else {
+ confirmed, err = term.ConfirmYesNo("Update context now?")
+ }
if err != nil {
panic(fmt.Errorf("failed to get user input: %s", err))
}
if confirmed {
- MustUpdateContext()
- }
-
- if canceled {
- os.Exit(0)
+ MustUpdateContext(maybeContexts)
}
+ return true, confirmed, canceled
}
-func MustUpdateContext() {
+func MustUpdateContext(maybeContexts []*shared.Context) {
term.StartSpinner("πŸ”„ Updating context...")
- updateRes, err := UpdateContext()
+ updateRes, err := UpdateContext(maybeContexts)
if err != nil {
term.StopSpinner()
@@ -122,19 +123,25 @@ func MustUpdateContext() {
}
-func UpdateContext() (*types.ContextOutdatedResult, error) {
- return checkOutdatedAndMaybeUpdateContext(true)
+func UpdateContext(maybeContexts []*shared.Context) (*types.ContextOutdatedResult, error) {
+ return checkOutdatedAndMaybeUpdateContext(true, maybeContexts)
}
-func CheckOutdatedContext() (*types.ContextOutdatedResult, error) {
- return checkOutdatedAndMaybeUpdateContext(false)
+func CheckOutdatedContext(maybeContexts []*shared.Context) (*types.ContextOutdatedResult, error) {
+ return checkOutdatedAndMaybeUpdateContext(false, maybeContexts)
}
-func checkOutdatedAndMaybeUpdateContext(doUpdate bool) (*types.ContextOutdatedResult, error) {
+func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Context) (*types.ContextOutdatedResult, error) {
+ var contexts []*shared.Context
- contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
- if err != nil {
- return nil, fmt.Errorf("error retrieving context: %v", err)
+ if maybeContexts == nil {
+ var apiErr *shared.ApiError
+ contexts, apiErr = api.Client.ListContext(CurrentPlanId, CurrentBranch)
+ if apiErr != nil {
+ return nil, fmt.Errorf("error retrieving context: %v", apiErr)
+ }
+ } else {
+ contexts = maybeContexts
}
var errs []error
@@ -297,7 +304,7 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool) (*types.ContextOutdatedRe
if hasConflicts {
term.StartSpinner("πŸ—οΈ Starting build...")
- _, err := buildPlanInlineFn()
+ _, err := buildPlanInlineFn(nil) // don't pass in outdated contexts -- nil value causes them to be refetched, which is what we want since they were just updated
if err != nil {
return nil, fmt.Errorf("failed to build plan: %v", err)
diff --git a/app/cli/main.go b/app/cli/main.go
index 2f99a060..6f8fe859 100644
--- a/app/cli/main.go
+++ b/app/cli/main.go
@@ -11,16 +11,20 @@ import (
"plandex/fs"
"plandex/lib"
"plandex/plan_exec"
+
+ "github.com/plandex/plandex/shared"
)
func init() {
// inter-package dependency injections to avoid circular imports
auth.SetApiClient(api.Client)
- lib.SetBuildPlanInlineFn(func() (bool, error) {
+ lib.SetBuildPlanInlineFn(func(maybeContexts []*shared.Context) (bool, error) {
return plan_exec.Build(plan_exec.ExecParams{
- CurrentPlanId: lib.CurrentPlanId,
- CurrentBranch: lib.CurrentBranch,
- CheckOutdatedContext: func() { lib.MustCheckOutdatedContext(true) },
+ CurrentPlanId: lib.CurrentPlanId,
+ CurrentBranch: lib.CurrentBranch,
+ CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
+ return lib.MustCheckOutdatedContext(cancelOpt, true, maybeContexts)
+ },
}, false)
})
diff --git a/app/cli/plan_exec/build.go b/app/cli/plan_exec/build.go
index 49545fe9..2f5a7aeb 100644
--- a/app/cli/plan_exec/build.go
+++ b/app/cli/plan_exec/build.go
@@ -2,6 +2,7 @@ package plan_exec
import (
"fmt"
+ "log"
"os"
"plandex/api"
"plandex/fs"
@@ -14,8 +15,6 @@ import (
)
func Build(params ExecParams, buildBg bool) (bool, error) {
- params.CheckOutdatedContext()
-
term.StartSpinner("πŸ—οΈ Starting build...")
contexts, apiErr := api.Client.ListContext(params.CurrentPlanId, params.CurrentBranch)
@@ -25,6 +24,14 @@ func Build(params ExecParams, buildBg bool) (bool, error) {
os.Exit(1)
}
+ anyOutdated, didUpdate, _ := params.CheckOutdatedContext(false, contexts)
+
+ if anyOutdated && !didUpdate {
+ term.StopSpinner()
+ log.Println("Build canceled")
+ return false, nil
+ }
+
projectPaths, _, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))
if err != nil {
diff --git a/app/cli/plan_exec/params.go b/app/cli/plan_exec/params.go
index 749e9021..309cbce5 100644
--- a/app/cli/plan_exec/params.go
+++ b/app/cli/plan_exec/params.go
@@ -1,7 +1,9 @@
package plan_exec
+import "github.com/plandex/plandex/shared"
+
type ExecParams struct {
CurrentPlanId string
CurrentBranch string
- CheckOutdatedContext func()
+ CheckOutdatedContext func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool)
}
diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.go
index 356a6290..b18675ed 100644
--- a/app/cli/plan_exec/tell.go
+++ b/app/cli/plan_exec/tell.go
@@ -23,8 +23,6 @@ func TellPlan(
tellNoBuild,
isUserContinue bool,
) {
- params.CheckOutdatedContext()
-
contexts, apiErr := api.Client.ListContext(params.CurrentPlanId, params.CurrentBranch)
if apiErr != nil {
@@ -32,6 +30,18 @@ func TellPlan(
os.Exit(1)
}
+ anyOutdated, didUpdate, canceled := params.CheckOutdatedContext(true, contexts)
+
+ if anyOutdated && !didUpdate && canceled {
+ term.StopSpinner()
+ if isUserContinue {
+ log.Println("Plan won't continue")
+ } else {
+ log.Println("Prompt not sent")
+ }
+ os.Exit(0)
+ }
+
projectPaths, _, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))
if err != nil {