Skip to content

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

Update CLI commands with improved rewind, diff, and execution handling

Dane Schneider27cbb0f2218f
diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.go
index b5ad2d77..7d38289d 100644
--- a/app/cli/cmd/apply.go
+++ b/app/cli/cmd/apply.go
@@ -13,7 +13,7 @@ import (
var autoCommit, skipCommit, autoExec bool
func init() {
- initApplyFlags(applyCmd)
+ initApplyFlags(applyCmd, false)
initExecScriptFlags(applyCmd)
RootCmd.AddCommand(applyCmd)
}
diff --git a/app/cli/cmd/build.go b/app/cli/cmd/build.go
index 1fb98cf7..59521892 100644
--- a/app/cli/cmd/build.go
+++ b/app/cli/cmd/build.go
@@ -26,11 +26,12 @@ func init() {
RootCmd.AddCommand(buildCmd)
initExecFlags(buildCmd, initExecFlagsParams{
- omitFile: true,
- omitNoBuild: true,
- omitEditor: true,
- omitStop: true,
- omitAutoContext: true,
+ omitFile: true,
+ omitNoBuild: true,
+ omitEditor: true,
+ omitStop: true,
+ omitAutoContext: true,
+ omitSmartContext: true,
})
}
diff --git a/app/cli/cmd/chat.go b/app/cli/cmd/chat.go
index 36aa4b45..bb9b0a54 100644
--- a/app/cli/cmd/chat.go
+++ b/app/cli/cmd/chat.go
@@ -25,11 +25,12 @@ func init() {
RootCmd.AddCommand(chatCmd)
initExecFlags(chatCmd, initExecFlagsParams{
- omitNoBuild: true,
- omitStop: true,
- omitBg: true,
- omitApply: true,
- omitExec: true,
+ omitNoBuild: true,
+ omitStop: true,
+ omitBg: true,
+ omitApply: true,
+ omitExec: true,
+ omitSmartContext: true,
})
}
diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.go
index ea54d115..d29b2134 100644
--- a/app/cli/cmd/continue.go
+++ b/app/cli/cmd/continue.go
@@ -50,6 +50,7 @@ func doContinue(cmd *cobra.Command, args []string) {
IsUserContinue: true,
ExecEnabled: !noExec,
AutoContext: tellAutoContext,
+ SmartContext: tellSmartContext,
AutoApply: tellAutoApply,
IsChatOnly: chatOnly,
}
diff --git a/app/cli/cmd/diffs.go b/app/cli/cmd/diffs.go
index 67d9040f..9500cbb2 100644
--- a/app/cli/cmd/diffs.go
+++ b/app/cli/cmd/diffs.go
@@ -23,6 +23,8 @@ var diffUiSideBySide = true
var diffUiLineByLine bool
var diffGit bool
+var fromTellMenu bool
+
var diffsCmd = &cobra.Command{
Use: "diff",
Aliases: []string{"diffs"},
@@ -38,6 +40,10 @@ func init() {
diffsCmd.Flags().BoolVar(&diffGit, "git", false, "Show diffs in git diff format")
diffsCmd.Flags().BoolVarP(&diffUiSideBySide, "side", "s", true, "Show diffs UI in side-by-side view")
diffsCmd.Flags().BoolVarP(&diffUiLineByLine, "line", "l", false, "Show diffs UI in line-by-line view")
+
+ diffsCmd.Flags().BoolVar(&fromTellMenu, "from-tell-menu", false, "Show diffs from the tell menu") //nolint:unused
+ diffsCmd.Flags().MarkHidden("from-tell-menu")
+
}
func diffs(cmd *cobra.Command, args []string) {
@@ -48,16 +54,24 @@ func diffs(cmd *cobra.Command, args []string) {
term.OutputNoCurrentPlanErrorAndExit()
}
+ term.StartSpinner("")
+
if diffGit {
showDiffUi = false
}
diffs, err := api.Client.GetPlanDiffs(lib.CurrentPlanId, lib.CurrentBranch, plainTextOutput || showDiffUi)
+ term.StopSpinner()
if err != nil {
term.OutputErrorAndExit("Error getting plan diffs: %v", err)
return
}
+ if len(diffs) == 0 {
+ term.OutputErrorAndExit("πŸ€·β€β™‚οΈ No pending changes")
+ return
+ }
+
if showDiffUi {
getNewListener := func() net.Listener {
outputFormat := "line-by-line"
@@ -138,12 +152,17 @@ func diffs(cmd *cobra.Command, args []string) {
fmt.Printf("%s for git diff format\n", color.New(color.Bold, term.ColorHiGreen).Sprintf("(g)"))
// fmt.Printf("%s to quit\n", color.New(color.Bold, term.ColorHiGreen).Sprintf("(q)"))
+ s := "to exit menu/continue"
+ if fromTellMenu {
+ s = "to go back"
+ }
+
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>"),
+ color.New(term.ColorHiMagenta, color.Bold).Sprintf("%s", s),
)
char, key, err := term.GetUserKeyInput()
diff --git a/app/cli/cmd/log.go b/app/cli/cmd/log.go
index 1dd6c0e7..7559fad8 100644
--- a/app/cli/cmd/log.go
+++ b/app/cli/cmd/log.go
@@ -6,7 +6,6 @@ import (
"plandex-cli/auth"
"plandex-cli/lib"
"plandex-cli/term"
- "regexp"
"time"
"github.com/spf13/cobra"
@@ -59,13 +58,11 @@ func runLog(cmd *cobra.Command, args []string) {
func convertTimestampsToLocal(input string) (string, error) {
t := time.Now()
zone, _ := t.Zone()
-
- parseFmt := "Mon Jan 2, 2006 | 3:04:05pm MST"
- re := regexp.MustCompile(`\w{3} \w{3} \d{1,2}, \d{4} \| \d{1,2}:\d{2}:\d{2}(am|pm) UTC`)
+ re := lib.GitLogTimestampRegex
// Function to convert matched timestamps assuming they are in UTC to local time.
replaceFunc := func(match string) string {
- t, err := time.Parse(parseFmt, match)
+ t, err := time.Parse(lib.GitLogTimestampFormat, match)
if err != nil {
// In case of an error, return the original match.
return match
diff --git a/app/cli/cmd/plan_exec_helpers.go b/app/cli/cmd/plan_exec_helpers.go
index 86cc8ccc..33bccf58 100644
--- a/app/cli/cmd/plan_exec_helpers.go
+++ b/app/cli/cmd/plan_exec_helpers.go
@@ -30,6 +30,7 @@ var tellStop bool
var tellNoBuild bool
var tellAutoApply bool
var tellAutoContext bool
+var tellSmartContext bool
var noExec bool
var autoDebug int
@@ -48,14 +49,15 @@ func init() {
}
type initExecFlagsParams struct {
- omitFile bool
- omitNoBuild bool
- omitEditor bool
- omitStop bool
- omitBg bool
- omitApply bool
- omitExec bool
- omitAutoContext bool
+ omitFile bool
+ omitNoBuild bool
+ omitEditor bool
+ omitStop bool
+ omitBg bool
+ omitApply bool
+ omitExec bool
+ omitAutoContext bool
+ omitSmartContext bool
}
func initExecFlags(cmd *cobra.Command, params initExecFlagsParams) {
@@ -81,9 +83,13 @@ func initExecFlags(cmd *cobra.Command, params initExecFlagsParams) {
cmd.Flags().BoolVar(&tellAutoContext, "auto-load-context", false, shared.ConfigSettingsByKey["auto-load-context"].Desc)
}
+ if !params.omitSmartContext {
+ cmd.Flags().BoolVar(&tellSmartContext, "smart-context", false, shared.ConfigSettingsByKey["smart-context"].Desc)
+ }
+
if !params.omitApply {
cmd.Flags().BoolVar(&tellAutoApply, "apply", false, "Automatically apply changes")
- initApplyFlags(cmd)
+ initApplyFlags(cmd, true)
}
if !params.omitExec {
@@ -96,9 +102,18 @@ func initExecFlags(cmd *cobra.Command, params initExecFlagsParams) {
}
}
-func initApplyFlags(cmd *cobra.Command) {
- cmd.Flags().BoolVar(&autoCommit, "commit", false, "Commit changes to git when --apply is passed")
- cmd.Flags().BoolVar(&skipCommit, "no-commit", false, "Skip committing changes to git when --apply is passed")
+func initApplyFlags(cmd *cobra.Command, applyFlag bool) {
+ commitDesc := "Commit changes to git"
+ if applyFlag {
+ commitDesc += " when --apply is passed"
+ }
+
+ skipCommitDesc := "Skip committing changes to git"
+ if applyFlag {
+ skipCommitDesc += " when --apply is passed"
+ }
+ cmd.Flags().BoolVarP(&autoCommit, "commit", "c", false, commitDesc)
+ cmd.Flags().BoolVar(&skipCommit, "skip-commit", false, skipCommitDesc)
}
func initExecScriptFlags(cmd *cobra.Command) {
@@ -164,6 +179,9 @@ func mustSetPlanExecFlags(cmd *cobra.Command) {
if !cmd.Flags().Changed("auto-load-context") {
tellAutoContext = config.AutoLoadContext
}
+ if !cmd.Flags().Changed("smart-context") {
+ tellSmartContext = config.SmartContext
+ }
if !cmd.Flags().Changed("no-exec") {
noExec = !config.CanExec
}
diff --git a/app/cli/cmd/repl.go b/app/cli/cmd/repl.go
index 13f14963..80c7b9ed 100644
--- a/app/cli/cmd/repl.go
+++ b/app/cli/cmd/repl.go
@@ -107,8 +107,8 @@ func runRepl(cmd *cobra.Command, args []string) {
func(in string) { executor(in, p) },
prompt.WithPrefixCallback(func() string {
// Get last part of current working directory
- cwd := fs.Cwd
- dirName := filepath.Base(cwd)
+ // cwd := fs.Cwd
+ // dirName := filepath.Base(cwd)
// Build prefix with directory and mode indicator
var modeIcon string
@@ -117,7 +117,7 @@ func runRepl(cmd *cobra.Command, args []string) {
} else if lib.CurrentReplState.Mode == lib.ReplModeChat {
modeIcon = "πŸ’¬"
}
- return fmt.Sprintf("%s %s ", dirName, modeIcon)
+ return fmt.Sprintf("%s ", modeIcon)
}),
prompt.WithTitle("Plandex "+version.Version),
prompt.WithSelectedSuggestionBGColor(prompt.LightGray),
@@ -473,7 +473,7 @@ func executor(in string, p *prompt.Prompt) {
}
if sel == beginImplOpt {
fmt.Println()
- args := []string{"tell", "Go ahead with the implementation based on what we've discussed so far."}
+ args := []string{"tell", "--from-chat"}
_, err := lib.ExecPlandexCommand(args)
if err != nil {
color.New(term.ColorHiRed).Printf("Error executing tell: %v\n", err)
diff --git a/app/cli/cmd/rewind.go b/app/cli/cmd/rewind.go
index bea0cca1..cd7f26e4 100644
--- a/app/cli/cmd/rewind.go
+++ b/app/cli/cmd/rewind.go
@@ -2,13 +2,16 @@ package cmd
import (
"fmt"
+ "os"
"plandex-cli/api"
"plandex-cli/auth"
+ "plandex-cli/fs"
"plandex-cli/lib"
"plandex-cli/term"
"regexp"
"strconv"
"strings"
+ "time"
shared "plandex-shared"
@@ -18,16 +21,33 @@ import (
var rewindCmd = &cobra.Command{
Use: "rewind [steps-or-sha]",
Aliases: []string{"rw"},
- Short: "Rewind the plan to an earlier state",
- Long: `Rewind the plan to an earlier state.
+ Short: "Rewind plan state and optionally revert project files",
+ Long: `Rewind plan state and optionally revert project files to match.
- You can pass a "steps" number or a commit sha. If a steps number is passed, the plan will be rewound that many steps. If a commit sha is passed, the plan will be rewound to that commit. If neither a steps number nor a commit sha is passed, you will be prompted to select a step from the history.`,
+You can pass a "steps" number or a commit sha. If a steps number is passed,
+the plan will be rewound that many steps. If a commit sha is passed, the
+plan will be rewound to that commit. If neither is passed, you will be
+prompted to select a step from the history.
+
+By default, you will be prompted whether to revert project files to match
+the rewound plan state. You can use --revert to automatically revert
+files, or configure this behavior with the 'auto-revert' plan config setting.
+
+If project files have changes, you will always be prompted before updating.`,
Args: cobra.MaximumNArgs(1),
Run: rewind,
}
+var revert bool
+var skipRevert bool
+
func init() {
RootCmd.AddCommand(rewindCmd)
+ rewindCmd.Flags().BoolVar(&revert, "revert", false, "Also revert project files to match plan state")
+ rewindCmd.Flags().BoolVar(&skipRevert, "skip-revert", false, "Skip reverting project files to match plan state")
+ rewindCmd.Flags().BoolVar(&autoCommit, "commit", false, "Commit changes to git when --revert is passed")
+ rewindCmd.Flags().BoolVar(&skipCommit, "skip-commit", false, "Skip committing changes to git when --revert is passed")
+
}
func rewind(cmd *cobra.Command, args []string) {
@@ -38,6 +58,10 @@ func rewind(cmd *cobra.Command, args []string) {
term.OutputNoCurrentPlanErrorAndExit()
}
+ if skipRevert && revert {
+ term.OutputErrorAndExit("Cannot pass both --revert and --skip-revert")
+ }
+
// Get logs
term.StartSpinner("")
logsRes, apiErr := api.Client.ListLogs(lib.CurrentPlanId, lib.CurrentBranch)
@@ -45,46 +69,54 @@ func rewind(cmd *cobra.Command, args []string) {
term.StopSpinner()
term.OutputErrorAndExit("Error getting logs: %v", apiErr)
}
- term.StopSpinner()
var targetSha string
var steps int
var isSha bool
+ parseGitLog := func(log string) (string, string) {
+ // Parse the log entry
+ lines := strings.Split(log, "\n")
+ if len(lines) < 2 {
+ return "", ""
+ }
+
+ // Extract sha and timestamp from first line
+ parts := strings.Split(lines[0], "|")
+ if len(parts) < 2 {
+ return "", ""
+ }
+
+ shaLine := strings.TrimSpace(parts[0])
+ sha := regexp.MustCompile(`πŸ“ Update (\w+)`).FindStringSubmatch(shaLine)[1]
+ msg := strings.TrimSpace(lines[1])
+
+ return sha, msg
+ }
+
+ logEntries := strings.Split(logsRes.Body, "\n\n")
+
if len(args) == 0 {
// No arguments - show selection list
options := make([]string, 0)
- logEntries := strings.Split(logsRes.Body, "\n\n")
for _, log := range logEntries {
if log == "" {
continue
}
- // Parse the log entry
- lines := strings.Split(log, "\n")
- if len(lines) < 2 {
- continue
- }
+ sha, msg := parseGitLog(log)
- // Extract sha and timestamp from first line
- // Format: πŸ“ Update 526c4a9[0;22m | [36mToday | 2:35:18am PST[0m
- parts := strings.Split(lines[0], "|")
- if len(parts) < 2 {
+ if sha == "" {
continue
}
- shaLine := strings.TrimSpace(parts[0])
- sha := regexp.MustCompile(`πŸ“ Update (\w+)`).FindStringSubmatch(shaLine)[1]
-
- // Get message from second line and format it
- msg := strings.TrimSpace(lines[1])
-
// Format the two-line option
option := fmt.Sprintf("%s | %s", sha, formatLogMessage(msg))
options = append(options, option)
}
+ term.StopSpinner()
selected, err := term.SelectFromList("Select step to rewind to:", options)
if err != nil {
term.OutputErrorAndExit("Error selecting step: %v", err)
@@ -116,30 +148,328 @@ func rewind(cmd *cobra.Command, args []string) {
}
}
- // Rewind to the target sha
- term.StartSpinner("")
- _, apiErr = api.Client.RewindPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.RewindPlanRequest{Sha: targetSha})
- term.StopSpinner()
+ doRewind := func() {
+ term.StartSpinner("")
+ _, apiErr := api.Client.RewindPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.RewindPlanRequest{
+ Sha: targetSha,
+ })
+ term.StopSpinner()
+
+ if apiErr != nil {
+ term.OutputErrorAndExit("Error rewinding plan: %v", apiErr)
+ }
+
+ var msg string
+ if isSha {
+ msg = "βœ… Rewound to " + targetSha
+ } else {
+ postfix := "s"
+ if steps == 1 {
+ postfix = ""
+ }
+ msg = fmt.Sprintf("βœ… Rewound %d step%s to %s", steps, postfix, targetSha)
+ }
+
+ fmt.Println(msg)
+ fmt.Println()
+ }
+ printNoChanges := func() {
+ fmt.Println("πŸ™…β€β™‚οΈ No project files were modified")
+ fmt.Println()
+ }
+
+ printCmds := func() {
+ term.PrintCmds("", "log", "continue")
+ }
+
+ // get the timestamp of the target sha
+ var targetShaTimestamp time.Time
+ for _, log := range logEntries {
+ if log == "" {
+ continue
+ }
+ sha, _ := parseGitLog(log)
+ if sha == targetSha {
+ timestamp, err := lib.GetGitLogTimestamp(log)
+ if err != nil {
+ continue
+ }
+
+ targetShaTimestamp = timestamp
+ break
+ }
+ }
+
+ if targetShaTimestamp.IsZero() {
+ term.OutputErrorAndExit("Error getting timestamp for target sha: " + targetSha)
+ }
+
+ // Get current plan state to check for undone applies
+ term.StartSpinner("")
+ currentState, apiErr := api.Client.GetCurrentPlanState(lib.CurrentPlanId, lib.CurrentBranch)
if apiErr != nil {
- term.OutputErrorAndExit("Error rewinding plan: %v", apiErr)
+ term.StopSpinner()
+ term.OutputErrorAndExit("Error getting plan state: %v", apiErr)
}
- var msg string
- if isSha {
- msg = "βœ… Rewound to " + targetSha
+ // Get list of applies that will be undone
+ undonePlanApplies := lib.GetUndonePlanApplies(currentState, targetShaTimestamp)
+
+ // If no applies are being undone, skip revert entirely
+ if len(undonePlanApplies) == 0 {
+ // Just do the rewind, no need for any file operations
+ doRewind()
+ printNoChanges()
+ printCmds()
+ return
+ }
+
+ // Get the set of affected file paths
+
+ // Determine if we should revert based on flag/config
+ var shouldRevert bool
+ needsPrompt := true
+ var config *shared.PlanConfig
+
+ if cmd.Flags().Changed("revert") || cmd.Flags().Changed("skip-revert") {
+ if skipRevert {
+ shouldRevert = false
+ } else {
+ shouldRevert = revert
+ }
+ needsPrompt = false
} else {
- postfix := "s"
- if steps == 1 {
- postfix = ""
+ config, apiErr = api.Client.GetPlanConfig(lib.CurrentPlanId)
+ if apiErr != nil {
+ term.OutputErrorAndExit("Error getting plan config: %v", apiErr)
+ }
+ shouldRevert = config.AutoRevertOnRewind
+ needsPrompt = false
+ }
+
+ var targetState *shared.CurrentPlanState
+ var analysis *lib.RewindAnalysis
+
+ if shouldRevert || needsPrompt {
+ // First preview the rewind to check for conflicts
+ targetState, apiErr = api.Client.GetCurrentPlanStateAtSha(lib.CurrentPlanId, targetSha)
+ if apiErr != nil {
+ term.OutputErrorAndExit("Error previewing rewind: %v", apiErr)
+ }
+
+ if targetState == nil {
+ term.OutputErrorAndExit("Error previewing rewind - no state found at sha: " + targetSha)
+ }
+
+ var err error
+ analysis, err = lib.AnalyzeRewind(targetState, currentState)
+ if err != nil {
+ term.StopSpinner()
+ term.OutputErrorAndExit("Error analyzing rewind: %v", err)
+ }
+
+ if len(analysis.RequiredChanges) == 0 {
+ // No file changes - proceed with rewind
+ doRewind()
+ printNoChanges()
+ printCmds()
+ return
+ }
+
+ // Show file differences
+ term.StopSpinner()
+
+ // Group changes by type for display
+ toAdd := make([]string, 0)
+ toRemove := make([]string, 0)
+ toModify := make([]string, 0)
+
+ for path, content := range analysis.RequiredChanges {
+ if content == "" {
+ toRemove = append(toRemove, path)
+ } else if currentState.ContextsByPath[path] == nil {
+ toAdd = append(toAdd, path)
+ } else {
+ toModify = append(toModify, path)
+ }
+ }
+
+ if needsPrompt || len(analysis.Conflicts) > 0 {
+ s := "files"
+ if len(analysis.RequiredChanges) == 1 {
+ s = "file"
+ }
+
+ fmt.Printf("βͺ %d local project %s differ from target plan state\n", len(analysis.RequiredChanges), s)
+ fmt.Println()
+ fmt.Printf("Reverting the %s will make these changes locally πŸ‘‡\n", s)
+ fmt.Println()
+
+ if len(toAdd) > 0 {
+ fmt.Println("To add:")
+ for _, path := range toAdd {
+ fmt.Printf(" β€’ %s\n", path)
+ }
+ fmt.Println()
+ }
+
+ if len(toRemove) > 0 {
+ fmt.Println("To remove:")
+ for _, path := range toRemove {
+ fmt.Printf(" β€’ %s\n", path)
+ }
+ fmt.Println()
+ }
+
+ if len(toModify) > 0 {
+ fmt.Println("To update:")
+ for _, path := range toModify {
+ fmt.Printf(" β€’ %s\n", path)
+ }
+ fmt.Println()
+ }
+
+ if len(analysis.Conflicts) > 0 {
+ // Always prompt if there are conflicts
+ s := " These project files have"
+ if len(analysis.Conflicts) == 1 {
+ s = " A project file has"
+ }
+ fmt.Printf("⚠️ %s been updated outside of Plandex since the latest apply:\n", s)
+ for path := range analysis.Conflicts {
+ fmt.Printf(" β€’ %s\n", path)
+ }
+ fmt.Println()
+
+ fmt.Println("If you revert, you will lose those changes.")
+ fmt.Println()
+
+ s = "files"
+ if len(analysis.RequiredChanges) == 1 {
+ s = "file"
+ }
+
+ options := []string{
+ fmt.Sprintf("Revert project %s to match rewound plan state (overwrite changes)", s),
+ fmt.Sprintf("Rewind plan, but skip reverting project %s", s),
+ "Cancel rewind",
+ }
+
+ selected, err := term.SelectFromList("What do you want to do?", options)
+ if err != nil {
+ term.OutputErrorAndExit("Error getting user input: %v", err)
+ }
+
+ switch selected {
+ case options[0]:
+ shouldRevert = true
+ case options[1]:
+ shouldRevert = false
+ case options[2]:
+ os.Exit(0)
+ }
+
+ needsPrompt = false
+ }
+ }
+ }
+
+ // Now that we've handled the file state decision, perform the actual rewind
+ doRewind()
+
+ didRevert := false
+
+ if shouldRevert || needsPrompt {
+ if needsPrompt {
+ term.StopSpinner()
+ s := "files"
+ if len(analysis.RequiredChanges) == 1 {
+ s = "file"
+ }
+ confirmed, err := term.ConfirmYesNo(fmt.Sprintf("Revert project %s to match rewound plan state?", s))
+ if err != nil {
+ term.OutputErrorAndExit("Error getting user confirmation: %v", err)
+ }
+
+ shouldRevert = confirmed
+ }
+
+ if shouldRevert && len(analysis.RequiredChanges) > 0 {
+ term.StartSpinner("")
+ err := lib.ApplyRewindChanges(analysis.RequiredChanges)
+ term.StopSpinner()
+ if err != nil {
+ term.OutputErrorAndExit("Error restoring file state: %v", err)
+ }
+
+ didRevert = true
+
+ s := "files were"
+ if len(analysis.RequiredChanges) == 1 {
+ s = "file was"
+ }
+
+ fmt.Printf("βͺ %d project %s reverted\n", len(analysis.RequiredChanges), s)
+ for path := range analysis.RequiredChanges {
+ fmt.Printf(" β€’ %s\n", path)
+ }
+ fmt.Println()
}
- msg = fmt.Sprintf("βœ… Rewound %d step%s to %s", steps, postfix, targetSha)
}
- fmt.Println(msg)
- fmt.Println()
+ if didRevert {
+ shouldCommit := false
+ needsPrompt := true
+
+ if cmd.Flags().Changed("commit") || cmd.Flags().Changed("skip-commit") {
+ if skipCommit {
+ shouldCommit = false
+ } else {
+ shouldCommit = autoCommit
+ }
+ needsPrompt = false
+ } else {
+ if config == nil {
+ config, apiErr = api.Client.GetPlanConfig(lib.CurrentPlanId)
+ if apiErr != nil {
+ term.OutputErrorAndExit("Error getting plan config: %v", apiErr)
+ }
+ }
+ shouldCommit = config.AutoCommit
+ needsPrompt = false
+ }
+
+ if needsPrompt {
+ term.StopSpinner()
+ confirmed, err := term.ConfirmYesNo("Commit changes to git?")
+ if err != nil {
+ term.OutputErrorAndExit("Error getting user confirmation: %v", err)
+ }
+ shouldCommit = confirmed
+ }
+
+ if shouldCommit {
+ msg := "πŸ€– Plandex β†’ rewound plan state and reverted these changes:"
+ for _, apply := range undonePlanApplies {
+ msg += fmt.Sprintf("\n β€’ %s", apply.CommitMsg)
+ }
+
+ paths := []string{}
+ for path := range analysis.RequiredChanges {
+ paths = append(paths, path)
+ }
+
+ err := lib.GitAddAndCommitPaths(fs.ProjectRoot, msg, paths, true)
+ if err != nil {
+ term.OutputErrorAndExit("Error committing changes: %v", err)
+ }
+ }
+ } else {
+ printNoChanges()
+ }
- term.PrintCmds("", "log", "continue")
+ printCmds()
}
func formatLogMessage(msg string) string {
diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.go
index 2d1c6f2d..3fe702c9 100644
--- a/app/cli/cmd/tell.go
+++ b/app/cli/cmd/tell.go
@@ -18,6 +18,8 @@ import (
"github.com/spf13/cobra"
)
+var isImplementationOfChat bool
+
// tellCmd represents the prompt command
var tellCmd = &cobra.Command{
Use: "tell [prompt]",
@@ -32,6 +34,8 @@ func init() {
RootCmd.AddCommand(tellCmd)
initExecFlags(tellCmd, initExecFlagsParams{})
+
+ tellCmd.Flags().BoolVar(&isImplementationOfChat, "from-chat", false, "Begin implementation based on conversation so far")
}
func doTell(cmd *cobra.Command, args []string) {
@@ -44,20 +48,29 @@ func doTell(cmd *cobra.Command, args []string) {
apiKeys = lib.MustVerifyApiKeys()
}
- prompt := getTellPrompt(args)
+ if isImplementationOfChat && len(args) > 0 {
+ term.OutputErrorAndExit("Error: --from-chat cannot be used with a prompt")
+ }
+
+ var prompt string
+ if !isImplementationOfChat {
+ prompt = getTellPrompt(args)
- if prompt == "" {
- fmt.Println("πŸ€·β€β™‚οΈ No prompt to send")
- return
+ if prompt == "" {
+ fmt.Println("πŸ€·β€β™‚οΈ No prompt to send")
+ return
+ }
}
tellFlags := types.TellFlags{
- TellBg: tellBg,
- TellStop: tellStop,
- TellNoBuild: tellNoBuild,
- AutoContext: tellAutoContext,
- ExecEnabled: !noExec,
- AutoApply: tellAutoApply,
+ TellBg: tellBg,
+ TellStop: tellStop,
+ TellNoBuild: tellNoBuild,
+ AutoContext: tellAutoContext,
+ SmartContext: tellSmartContext,
+ ExecEnabled: !noExec,
+ AutoApply: tellAutoApply,
+ IsImplementationOfChat: isImplementationOfChat,
}
plan_exec.TellPlan(plan_exec.ExecParams{
diff --git a/app/cli/plan_exec/action_menu.go b/app/cli/plan_exec/action_menu.go
index 73365078..b5a5bbf7 100644
--- a/app/cli/plan_exec/action_menu.go
+++ b/app/cli/plan_exec/action_menu.go
@@ -181,7 +181,7 @@ func handleHotkeyOption(option hotkeyOption, diffs []string, params ExecParams)
if option.char == "d" {
fmt.Println()
- _, err := lib.ExecPlandexCommandWithParams([]string{"diffs", "--ui"}, lib.ExecPlandexCommandParams{
+ _, err := lib.ExecPlandexCommandWithParams([]string{"diffs", "--ui", "--from-tell-menu"}, lib.ExecPlandexCommandParams{
DisableSuggestions: true,
})
if err != nil {
diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.go
index 07d68d8c..6a912b28 100644
--- a/app/cli/plan_exec/tell.go
+++ b/app/cli/plan_exec/tell.go
@@ -14,7 +14,6 @@ import (
shared "plandex-shared"
- "github.com/davecgh/go-spew/spew"
"github.com/fatih/color"
)
@@ -23,8 +22,6 @@ func TellPlan(
prompt string,
flags types.TellFlags,
) {
- log.Println("plan_exec.TellPlan")
- log.Println("flags", spew.Sdump(flags))
tellBg := flags.TellBg
tellStop := flags.TellStop
@@ -33,12 +30,17 @@ func TellPlan(
isDebugCmd := flags.IsUserDebug
isChatOnly := flags.IsChatOnly
autoContext := flags.AutoContext
+ smartContext := flags.SmartContext
execEnabled := flags.ExecEnabled
autoApply := flags.AutoApply
isApplyDebug := flags.IsApplyDebug
-
+ isImplementationOfChat := flags.IsImplementationOfChat
done := make(chan struct{})
+ if prompt == "" && isImplementationOfChat {
+ prompt = "Go ahead with the plan based on what we've discussed so far."
+ }
+
outputPromptIfTell := func() {
if isUserContinue || prompt == "" {
return
@@ -126,22 +128,24 @@ func TellPlan(
}
apiErr := api.Client.TellPlan(params.CurrentPlanId, params.CurrentBranch, shared.TellPlanRequest{
- Prompt: prompt,
- ConnectStream: !tellBg,
- AutoContinue: !tellStop,
- ProjectPaths: paths.ActivePaths,
- BuildMode: buildMode,
- IsUserContinue: isUserContinue,
- IsUserDebug: isDebugCmd,
- IsChatOnly: isChatOnly,
- AutoContext: autoContext,
- ExecEnabled: execEnabled,
- OsDetails: osDetails,
- ApiKey: legacyApiKey, // deprecated
- Endpoint: openAIBase, // deprecated
- ApiKeys: params.ApiKeys,
- OpenAIBase: openAIBase,
- OpenAIOrgId: openAIOrgId,
+ Prompt: prompt,
+ ConnectStream: !tellBg,
+ AutoContinue: !tellStop,
+ ProjectPaths: paths.ActivePaths,
+ BuildMode: buildMode,
+ IsUserContinue: isUserContinue,
+ IsUserDebug: isDebugCmd,
+ IsChatOnly: isChatOnly,
+ AutoContext: autoContext,
+ SmartContext: smartContext,
+ ExecEnabled: execEnabled,
+ OsDetails: osDetails,
+ ApiKey: legacyApiKey, // deprecated
+ Endpoint: openAIBase, // deprecated
+ ApiKeys: params.ApiKeys,
+ OpenAIBase: openAIBase,
+ OpenAIOrgId: openAIOrgId,
+ IsImplementationOfChat: isImplementationOfChat,
}, stream.OnStreamPlan)
term.StopSpinner()
diff --git a/app/cli/types/api.go b/app/cli/types/api.go
index eb060f96..36c238cb 100644
--- a/app/cli/types/api.go
+++ b/app/cli/types/api.go
@@ -68,6 +68,7 @@ type ApiClient interface {
RenamePlan(planId string, name string) *shared.ApiError
GetCurrentPlanState(planId, branch string) (*shared.CurrentPlanState, *shared.ApiError)
+ GetCurrentPlanStateAtSha(planId, sha string) (*shared.CurrentPlanState, *shared.ApiError)
ApplyPlan(planId, branch string, req shared.ApplyPlanRequest) (string, *shared.ApiError)
RejectAllChanges(planId, branch string) *shared.ApiError
RejectFile(planId, branch, filePath string) *shared.ApiError
diff --git a/app/cli/types/exec.go b/app/cli/types/exec.go
index 92e495d5..3e8d73a1 100644
--- a/app/cli/types/exec.go
+++ b/app/cli/types/exec.go
@@ -1,17 +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
+ TellBg bool
+ TellStop bool
+ TellNoBuild bool
+ IsUserContinue bool
+ IsUserDebug bool
+ IsApplyDebug bool
+ IsChatOnly bool
+ AutoContext bool
+ SmartContext bool
+ ContinuedAfterAction bool
+ ExecEnabled bool
+ AutoApply bool
+ IsImplementationOfChat bool
}
type BuildFlags struct {
BuildBg bool