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
'chat' command for questions/chatting without any changes
Dane Schneider2f62eeb01d65
diff --git a/app/cli/cmd/chat.go b/app/cli/cmd/chat.gonew file mode 100644index 00000000..553cca3d--- /dev/null+++ b/app/cli/cmd/chat.go@@ -0,0 +1,58 @@+package cmd++import (+ "fmt"+ "plandex/auth"+ "plandex/lib"+ "plandex/plan_exec"+ "plandex/term"++ "github.com/plandex/plandex/shared"+ "github.com/spf13/cobra"+)++var chatCmd = &cobra.Command{+ Use: "chat [prompt]",+ Aliases: []string{"c"},+ Short: "Chat without making changes",+ // Long: ``,+ Args: cobra.RangeArgs(0, 1),+ Run: doChat,+}++func init() {+ RootCmd.AddCommand(chatCmd)++ chatCmd.Flags().StringVarP(&tellPromptFile, "file", "f", "", "File containing prompt")+ chatCmd.Flags().BoolVarP(&autoConfirm, "yes", "y", false, "Automatically confirm context updates")+}++func doChat(cmd *cobra.Command, args []string) {+ auth.MustResolveAuthWithOrg()+ lib.MustResolveProject()++ if lib.CurrentPlanId == "" {+ term.OutputNoCurrentPlanErrorAndExit()+ }++ var apiKeys map[string]string+ if !auth.Current.IntegratedModelsMode {+ apiKeys = lib.MustVerifyApiKeys()+ }++ prompt := getTellPrompt(args)++ if prompt == "" {+ fmt.Println("🤷♂️ No prompt to send")+ return+ }++ plan_exec.TellPlan(plan_exec.ExecParams{+ CurrentPlanId: lib.CurrentPlanId,+ CurrentBranch: lib.CurrentBranch,+ ApiKeys: apiKeys,+ CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {+ return lib.CheckOutdatedContextWithOutput(false, autoConfirm, maybeContexts)+ },+ }, prompt, false, false, false, false, false, true)+}diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.goindex 7cadb895..8829a254 100644--- a/app/cli/cmd/tell.go+++ b/app/cli/cmd/tell.go@@ -16,7 +16,6 @@ import ("github.com/spf13/cobra")-// testconst defaultEditor = "vim"// const defaultEditor = "nano"@@ -66,6 +65,28 @@ func doTell(cmd *cobra.Command, args []string) {apiKeys = lib.MustVerifyApiKeys()}+ prompt := getTellPrompt(args)++ if prompt == "" {+ fmt.Println("🤷♂️ No prompt to send")+ return+ }++ plan_exec.TellPlan(plan_exec.ExecParams{+ CurrentPlanId: lib.CurrentPlanId,+ CurrentBranch: lib.CurrentBranch,+ ApiKeys: apiKeys,+ CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {+ return lib.CheckOutdatedContextWithOutput(false, autoConfirm || tellAutoApply, maybeContexts)+ },+ }, prompt, tellBg, tellStop, tellNoBuild, false, false, false)++ if tellAutoApply {+ lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, true, autoCommit, !autoCommit)+ }+}++func getTellPrompt(args []string) string {var prompt stringvar pipedData string@@ -104,23 +125,7 @@ func doTell(cmd *cobra.Command, args []string) {}}- if prompt == "" {- fmt.Println("🤷♂️ No prompt to send")- return- }-- plan_exec.TellPlan(plan_exec.ExecParams{- CurrentPlanId: lib.CurrentPlanId,- CurrentBranch: lib.CurrentBranch,- ApiKeys: apiKeys,- CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {- return lib.CheckOutdatedContextWithOutput(false, autoConfirm || tellAutoApply, maybeContexts)- },- }, prompt, tellBg, tellStop, tellNoBuild, false, false, false)-- if tellAutoApply {- lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, true, autoCommit, !autoCommit)- }+ return prompt}func prepareEditorCommand(editor string, filename string) *exec.Cmd {diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.goindex 3cd51cf3..06669bde 100644--- a/app/cli/plan_exec/tell.go+++ b/app/cli/plan_exec/tell.go@@ -69,7 +69,9 @@ func TellPlan(os.Exit(0)}+ term.StartSpinner("")paths, err := fs.GetProjectPaths(fs.GetBaseDirForContexts(contexts))+ term.StopSpinner()if err != nil {outputPromptIfTell()@@ -80,7 +82,7 @@ func TellPlan(fn = func() bool {var buildMode shared.BuildMode- if tellNoBuild {+ if tellNoBuild || isChatOnly {buildMode = shared.BuildModeNone} else {buildMode = shared.BuildModeAuto@@ -112,6 +114,7 @@ func TellPlan(BuildMode: buildMode,IsUserContinue: isUserContinue,IsUserDebug: isDebugCmd,+ IsChatOnly: isChatOnly,ApiKey: legacyApiKey, // deprecatedEndpoint: openAIBase, // deprecatedApiKeys: params.ApiKeys,@@ -162,10 +165,12 @@ func TellPlan(fmt.Println()- if tellStop {+ if tellStop && !isChatOnly {term.PrintCmds("", "continue", "diff", "diff --ui", "apply", "reject", "log", "rewind")- } else if !isDebugCmd {+ } else if !isDebugCmd && !isChatOnly {term.PrintCmds("", "diff", "diff --ui", "apply", "reject", "debug", "log", "rewind")+ } else if isChatOnly {+ term.PrintCmds("", "tell", "convo", "summary")}close(done)}()diff --git a/app/cli/term/help.go b/app/cli/term/help.goindex 8555219c..3082ca01 100644--- a/app/cli/term/help.go+++ b/app/cli/term/help.go@@ -14,8 +14,9 @@ var CmdDesc = map[string][2]string{"rename": {"", "rename the current plan"},"current": {"cu", "show current plan"},"cd": {"", "set current plan by name or index"},- "load": {"l", "load files, dirs, urls, notes, images, or piped data into context"},- "tell": {"t", "describe a task, ask a question, or chat"},+ "load": {"l", "load files/dirs/urls/notes/images or pipe data into context"},+ "tell": {"t", "describe a task to complete"},+ "chat": {"", "ask a question or chat without making any changes"},"changes": {"ch", "review pending changes in a TUI"},"diff": {"", "review pending changes in 'git diff' format"},"diff --plain": {"", "review pending changes in 'git diff' format with no color formatting"},@@ -27,7 +28,7 @@ var CmdDesc = map[string][2]string{"archive": {"arc", "archive a plan"},"unarchive": {"unarc", "unarchive a plan"},"continue": {"c", "continue the plan"},- "debug": {"", "repeatedly run a command and make fixes until it succeeds"},+ "debug": {"", "repeatedly run a command and auto-apply fixes until it succeeds"},// "status": {"s", "show status of the plan"},"rewind": {"rw", "rewind to a previous state"},"ls": {"", "list everything in context"},@@ -136,12 +137,12 @@ func PrintCustomHelp(all bool) {fmt.Fprintln(builder)fmt.Fprintf(builder, " 2 - Load any relevant context with %s\n", color.New(color.Bold, color.BgCyan, color.FgHiWhite).Sprint(" plandex load [file-path-or-url] "))fmt.Fprintln(builder)- fmt.Fprintf(builder, " 3 - Describe a task, ask a question, or chat with %s\n", color.New(color.Bold, color.BgCyan, color.FgHiWhite).Sprint(" plandex tell "))+ fmt.Fprintf(builder, " 3 - Describe a task to complete with %s\n", color.New(color.Bold, color.BgCyan, color.FgHiWhite).Sprint(" plandex tell "))fmt.Fprintln(builder)if all {color.New(color.Bold, color.BgMagenta, color.FgHiWhite).Fprintln(builder, " Key Commands ")- printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiMagenta}, "new", "load", "tell", "diff", "diff --ui", "apply", "reject", "debug")+ printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiMagenta}, "new", "load", "tell", "diff", "diff --ui", "apply", "reject", "debug", "chat")fmt.Fprintln(builder)color.New(color.Bold, color.BgCyan, color.FgHiWhite).Fprintln(builder, " Plans ")@@ -165,7 +166,7 @@ func PrintCustomHelp(all bool) {fmt.Fprintln(builder)color.New(color.Bold, color.BgCyan, color.FgHiWhite).Fprintln(builder, " Control ")- printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiCyan}, "tell", "continue", "build", "debug")+ printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiCyan}, "tell", "continue", "build", "debug", "chat")fmt.Fprintln(builder)color.New(color.Bold, color.BgCyan, color.FgHiWhite).Fprintln(builder, " Streams ")diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 99deeeb3..0ba65015 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -36,7 +36,7 @@ func Tell(clients map[string]*openai.Client, plan *db.Plan, branch string, authreq,0,"",- req.BuildMode == shared.BuildModeAuto,+ !req.IsChatOnly && req.BuildMode == shared.BuildModeAuto,"","",0,@@ -320,8 +320,11 @@ func execTellPlan(} else {var prompt stringif iteration == 0 {- if req.IsUserDebug {- prompt = prompts.DebugPrompt + req.Prompt+ if req.IsChatOnly {+ prompt = req.Prompt + prompts.ChatOnlyPrompt+ state.totalRequestTokens += prompts.ChatOnlyPromptTokens+ } else if req.IsUserDebug {+ prompt = req.Prompt + prompts.DebugPromptstate.totalRequestTokens += prompts.DebugPromptTokens} else {prompt = req.Prompt@@ -369,6 +372,11 @@ func execTellPlan(}}+ if iteration > 0 && verifyDiffs == "" && active.ShouldVerifyDiff() {+ prompt += prompts.WillVerifyPrompt+ state.totalRequestTokens += prompts.WillVerifyPromptTokens+ }+state.userPrompt = promptpromptMessage = &openai.ChatCompletionMessage{diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex afe42215..fe98c863 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -387,7 +387,7 @@ mainLoop:ap.CurrentReplyDoneCh = nil})- if req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations {+ if !req.IsChatOnly && req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations {log.Println("Auto continue plan")// continue planexecTellPlan(clients, plan, branch, auth, req, iteration+1, "", false, nextTask, "", 0)@@ -489,6 +489,7 @@ mainLoop:// Handle file that is present in project paths but not in context// Prompt user for what to do on the client side, stop the stream, and wait for user response before proceedingif currentFile != "" &&+ !req.IsChatOnly &&active.ContextsByPath[currentFile] == nil &&req.ProjectPaths[currentFile] && !active.AllowOverwritePaths[currentFile] {log.Printf("Attempting to overwrite a file that isn't in context: %s\n", currentFile)@@ -572,7 +573,7 @@ mainLoop:// log.Println("replyFiles:")// spew.Dump(replyFiles)- if len(files) > len(replyFiles) {+ if !req.IsChatOnly && len(files) > len(replyFiles) {log.Printf("%d new files\n", len(files)-len(replyFiles))for i, file := range files {diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.goindex 4d77be41..025ae080 100644--- a/app/server/model/prompts/create.go+++ b/app/server/model/prompts/create.go@@ -12,7 +12,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context`First, decide if the user has a task for you.- *If the user doesn't have a task and is just asking a question or chatting*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but don't include labelled code blocks as described below, since that indicates that a plan is being created. If a plan is in progress, follow the instructions below.+ *If the user doesn't have a task and is just asking a question or chatting, or if 'chat mode' is enabled*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but don't include labelled code blocks as described below, since that indicates that a plan is being created. If a plan is in progress, follow the instructions below.*If the user does have a task*, create a plan for the task based on user-provided context using the following steps:@@ -178,7 +178,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context- If you think the plan is done, say so, but remember that you don't have the final word on the matter. Explain why you think the plan is done.- - If you think the plan is done and any file blocks have been used in the plan: unless the diffs for the plan have been supplied to you in the prompt for you to verify, state that you think the plan is done (as described above), but that you will proceed to verify the generated files before the plan is fully complete.+ - If you think the plan is done and any files in context have been *updated* during the plan: unless the diffs for the plan have been supplied to you in the prompt for you to verify, state that you think the plan is done (as described above), but that you will proceed to verify the generated files before the plan is fully complete. You ABSOLUTELY MUST NOT state that the plan is complete after updating any files in context—if you believe all the steps in the plan have been completed, you must instead state that all steps have been implemented, and that next you will proceed to check over the changes and fix any problems.## EXTREMELY IMPORTANT Rules for responses@@ -300,6 +300,12 @@ Here are the diffs:var VerifyDiffsPromptTokens int+const WillVerifyPrompt = `+Once all steps in this plan's implementation are complete, there will be an additional step where you will verify the diffs and fix any problems. Therefore, you MUST NOT tell the user that the plan is complete yet. Instead, tell the user that all steps in the plan have been implemented, and that next your will proceed to check over the changes and fix any problems. This *takes precedence* over your previous instructions on what to do after the plan is complete.+`++var WillVerifyPromptTokens int+const DebugPrompt = `You are debugging a failing shell command. Focus only on fixing this issue so that the command runs successfully; don't make other changes.Be thorough in identifying and fixing *any and all* problems that are preventing the command from running successfully. If there are multiple problems, identify and fix all of them.@@ -311,6 +317,16 @@ Command details:var DebugPromptTokens int+const ChatOnlyPrompt = `+**CHAT MODE IS ENABLED.**++Respond to the user in *chat form* only. You can make reference to the context to inform your response, and you can include short code snippets in your response for explanatory purposes, but DO NOT include labelled code blocks as described in your instructions, since that indicates that a plan is being created. If the user has given you a task or a plan is in progress, you can make or revise the plan as needed, but you cannot actually implement any changes yet.++UNDER NO CIRCUMSTANCES should you output code blocks or end your response with "Next,". Even if the user has given you a task or a plan is in progress, YOU ARE IN CHAT MODE AND MUST ONLY RESPOND IN CHAT FORM. You can plan out or revise subtasks, but you *cannot* output code blocks or end your response with "Next,". Again, DO NOT implement any changes or output code blocks!! Chat mode takes precedence over your prior instructions and the user's prompt under all circumstances—you MUST respond only in chat form regardless of what the user's prompt or your prior instructions say.+`++var ChatOnlyPromptTokens int+func init() {var err errorCreateSysMsgNumTokens, err = shared.GetNumTokens(SysCreate)@@ -342,6 +358,12 @@ func init() {if err != nil {panic(fmt.Sprintf("Error getting number of tokens for debug prompt: %v", err))}++ ChatOnlyPromptTokens, err = shared.GetNumTokens(ChatOnlyPrompt)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for chat only prompt: %v", err))+ }}const UpdateFormatPrompt = `