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
change 'next' to 'continue'--prompt improvements
Dane Schneiderddcd1e5d2286
diff --git a/cli/cmd/apply.go b/cli/cmd/apply.goindex 324810c3..e7e9cc36 100644--- a/cli/cmd/apply.go+++ b/cli/cmd/apply.go@@ -2,7 +2,6 @@ package cmdimport ("fmt"- "log""os""path/filepath""plandex/lib"@@ -33,27 +32,33 @@ func apply(cmd *cobra.Command, args []string) error {}if err != nil {- return fmt.Errorf("Error: %v", err)+ return fmt.Errorf("error: %v", err)}if name == "" || name == "current" {name = lib.CurrentPlanName}- // Check git installed- if !lib.IsCommandAvailable("git") {- log.Fatalln("Error: git is required")- }-rootDir := filepath.Join(plandexDir, name)if _, err := os.Stat(rootDir); os.IsNotExist(err) {- return fmt.Errorf("Error: plan with name '%+v' does not exist", name)+ return fmt.Errorf("error: plan with name '%+v' does not exist", name)}+ // isRepo := lib.CwdIsGitRepo()++ // if isRepo {++ // planState, err := lib.GetPlanState()+ // if err != nil {+ // return fmt.Errorf("error loading plan state: %v", err)+ // }++ // }+copiedAny := false- // Enumerate all paths in [planDir]/files- filesDir := filepath.Join(rootDir, "plan", "files")+ // Enumerate all paths in [draftDir]/files+ filesDir := filepath.Join(rootDir, "draft", "files")err = filepath.Walk(filesDir, func(srcPath string, info os.FileInfo, err error) error {if err != nil {return err@@ -81,13 +86,13 @@ func apply(cmd *cobra.Command, args []string) error {})if err != nil {- return fmt.Errorf("Error processing files: %v", err)+ return fmt.Errorf("error processing files: %v", err)}if copiedAny {fmt.Println("✅ Applied changes")} else {- return fmt.Errorf("This plan has no changes to apply.")+ return fmt.Errorf("this plan has no changes to apply")}return nildiff --git a/cli/cmd/next.go b/cli/cmd/continue.gosimilarity index 67%rename from cli/cmd/next.gorename to cli/cmd/continue.goindex f59baae9..69fa6eef 100644--- a/cli/cmd/next.go+++ b/cli/cmd/continue.go@@ -9,13 +9,13 @@ import ()// Variables to be used in the nextCmd-var prompt string = "continue to the next step of the plan"+const continuePrompt = "continue the plan"// nextCmd represents the prompt commandvar nextCmd = &cobra.Command{- Use: "next",- Aliases: []string{"n"},- Short: "Continue to the next step of the plan.",+ Use: "continue",+ Aliases: []string{"c"},+ Short: "Continue the plan.",Run: next,}@@ -24,7 +24,7 @@ func init() {}func next(cmd *cobra.Command, args []string) {- err := lib.Propose(prompt)+ err := lib.Propose(continuePrompt)if err != nil {fmt.Fprintln(os.Stderr, "Prompt error:", err)returndiff --git a/cli/cmd/current.go b/cli/cmd/current.goindex 2e2cfb52..a2f42a72 100644--- a/cli/cmd/current.go+++ b/cli/cmd/current.go@@ -1,28 +1,28 @@package cmd-import (- "fmt"- "plandex/lib"+// import (+// "fmt"+// "plandex/lib"- "github.com/spf13/cobra"-)+// "github.com/spf13/cobra"+// )-var currentCmd = &cobra.Command{- Use: "current",- Aliases: []string{"c"},- Short: "Get the current plan",- Run: current,-}+// var currentCmd = &cobra.Command{+// Use: "current",+// Aliases: []string{"c"},+// Short: "Get the current plan",+// Run: current,+// }-func init() {- RootCmd.AddCommand(currentCmd)-}+// func init() {+// RootCmd.AddCommand(currentCmd)+// }-func current(cmd *cobra.Command, args []string) {- if lib.CurrentPlanName == "" {- fmt.Println("No current plan.")- return- }- fmt.Println(lib.CurrentPlanName)+// func current(cmd *cobra.Command, args []string) {+// if lib.CurrentPlanName == "" {+// fmt.Println("No current plan.")+// return+// }+// fmt.Println(lib.CurrentPlanName)-}+// }diff --git a/cli/cmd/new.go b/cli/cmd/new.goindex 8b541af2..371374e6 100644--- a/cli/cmd/new.go+++ b/cli/cmd/new.go@@ -18,8 +18,9 @@ var name string// newCmd represents the new commandvar newCmd = &cobra.Command{- Use: "new",- Short: "Start a new plan.",+ Use: "new",+ Aliases: []string{"n"},+ Short: "Start a new plan.",// Long: ``,Args: cobra.ExactArgs(0),Run: new,diff --git a/cli/lib/fs.go b/cli/lib/fs.goindex d606513e..5ff9ac5d 100644--- a/cli/lib/fs.go+++ b/cli/lib/fs.go@@ -8,6 +8,8 @@ import ("path/filepath""plandex/types""sync"++ "github.com/plandex/plandex/shared")var Cwd string@@ -248,6 +250,37 @@ func CopyDir(srcDir, dstDir string) error {return nil}+func GetLatestPlanDescription() (*shared.PlanDescription, error) {+ // List files in descriptions directory+ entries, err := os.ReadDir(DescriptionsDir)+ if err != nil {+ return nil, err+ }++ // Find the latest file (named by timestamp)+ var latestFile os.DirEntry+ for _, entry := range entries {+ if latestFile == nil || entry.Name() > latestFile.Name() {+ latestFile = entry+ }+ }++ // Read the contents of the latest file+ bytes, err := os.ReadFile(filepath.Join(DescriptionsDir, latestFile.Name()))+ if err != nil {+ return nil, fmt.Errorf("error reading latest description file: %v", err)+ }++ // Unmarshal the JSON data into the shared.PlanDescription type+ var description shared.PlanDescription+ err = json.Unmarshal(bytes, &description)+ if err != nil {+ return nil, fmt.Errorf("error unmarshalling latest description file: %v", err)+ }++ return &description, nil+}+func findPlandex() (string, string) {searchPath := Cwdfor searchPath != "/" {diff --git a/cli/lib/git.go b/cli/lib/git.goindex 46002ab1..0273141b 100644--- a/cli/lib/git.go+++ b/cli/lib/git.go@@ -104,6 +104,19 @@ func GitCommit(repoDir, commitMsg string, lockMutex bool) error {return nil}+func CwdIsGitRepo() bool {+ isGitRepo := false+ if IsCommandAvailable("git") {+ // check whether we're in a git repo+ _, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()+ if err == nil {+ isGitRepo = true+ }+ }++ return isGitRepo+}+func gitCommitRootUpdate(commitMsg string) error {err := GitAdd(CurrentPlanDir, ".", true)if err != nil {diff --git a/cli/lib/proposal.go b/cli/lib/proposal.goindex 304b0428..fcffb795 100644--- a/cli/lib/proposal.go+++ b/cli/lib/proposal.go@@ -19,6 +19,8 @@ import ("github.com/briandowns/spinner")+const replyStreamThrottle = 70 * time.Millisecond+type key struct {value rune}@@ -68,7 +70,7 @@ func Propose(prompt string) error {termState := ""- replyUpdateTimer := time.NewTimer(100 * time.Millisecond)+ replyUpdateTimer := time.NewTimer(150 * time.Millisecond)defer replyUpdateTimer.Stop()var proposalId string@@ -78,6 +80,7 @@ func Propose(prompt string) error {var state *fsm.FSMvar streamFinished boolvar filesFinished bool+ var lastReplyTokenAdded time.TimefinishedByPath := make(map[string]bool)numStreamedTokensByPath := make(map[string]int)@@ -265,13 +268,21 @@ func Propose(prompt string) error {alternateScreen()replyStarted = true+ lastReplyTokenAdded = time.Now()}switch state.Current() {case shared.STATE_REPLYING:+ elapsed := time.Since(lastReplyTokenAdded)++ if elapsed < replyStreamThrottle {+ time.Sleep(replyStreamThrottle - elapsed)+ }+reply += contentreplyTokenCounter.AddToken(content, true)terminalHasPendingUpdate = true+ lastReplyTokenAdded = time.Now()case shared.STATE_FINISHED:s.Stop()@@ -419,7 +430,6 @@ Loop:}if desc != nil {-if desc.MadePlan && len(desc.Files) > 0 {fmt.Println()for _, cmd := range []string{"apply", "diffs", "preview"} {@@ -432,7 +442,10 @@ Loop:PrintCustomCmd(" ", "tell", "t", "update the plan, give more info, or chat")ClearCurrentLine()- PrintCmds(" ", "next")+ PrintCmds(" ", "continue")++ ClearCurrentLine()+ PrintCmds(" ", "rewind")}return nildiff --git a/cli/lib/term.go b/cli/lib/term.goindex 32893a90..41a38868 100644--- a/cli/lib/term.go+++ b/cli/lib/term.go@@ -12,17 +12,17 @@ import ()var cmdDesc = map[string][2]string{- "new": {"", "start a new plan"},- "current": {"c", "show current plan"},+ "new": {"", "start a new plan"},+ // "current": {"c", "show current plan"},"cd": {"", "set current plan by name or index"},- "load": {"l", "load files/directories/urls/strings or pipe data into context"},+ "load": {"l", "load files/directories/urls/notes or pipe data into context"},"tell": {"t", "describe a task, ask a question, or chat"},"diffs": {"d", "show diffs between plan and project files"},- "preview": {"p", "preview the plan in a branch"},+ "preview": {"pv", "preview the plan in a branch"},"apply": {"ap", "apply the plan to your project files"},- "next": {"n", "continue to next step of the plan"},+ "continue": {"c", "continue the plan"},"status": {"s", "show status of the plan"},- "rewind": {"rw", "rewind the plan to a previous step or state"},+ "rewind": {"rw", "rewind to a previous step or state"},"ls": {"", "list everything in context"},"rm": {"", "remove context by name, index, or glob"},"clear": {"", "remove all context"},@@ -42,6 +42,7 @@ func PrintCmds(prefix string, cmds ...string) {desc := config[1]if alias != "" {cmd = strings.Replace(cmd, alias, fmt.Sprintf("(%s)", alias), 1)+ // desc += color.New(color.FgWhite).Sprintf(" • alias → %s", color.New(color.Bold).Sprint(alias))}styled := color.New(color.Bold, color.FgHiWhite, color.BgCyan).Sprintf(" plandex %s ", cmd)@@ -51,6 +52,7 @@ func PrintCmds(prefix string, cmds ...string) {func PrintCustomCmd(prefix, cmd, alias, desc string) {cmd = strings.Replace(cmd, alias, fmt.Sprintf("(%s)", alias), 1)+ // desc += color.New(color.FgWhite).Sprintf(" • alias → %s", color.New(color.Bold).Sprint(alias))styled := color.New(color.Bold, color.FgHiWhite, color.BgCyan).Sprintf(" plandex %s ", cmd)fmt.Printf("%s%s 👉 %s\n", prefix, styled, desc)}diff --git a/cli/types/types.go b/cli/types/types.goindex 3aaf3021..0d726ce2 100644--- a/cli/types/types.go+++ b/cli/types/types.go@@ -51,6 +51,9 @@ type PlanState struct {ConvoTokens int `json:"convoTokens"`ConvoSummarizedTokens int `json:"convoSummarizedTokens"`NumMessages int `json:"numMessages"`+ AppliedAt string `json:"appliedAt"`+ BaseBranch string `json:"baseBranch"`+ PreviewBranch string `json:"previewBranch"`}type PlanSettings struct {diff --git a/server/model/openai_models.go b/server/model/openai_models.goindex 1a2cc2a8..c180bd7f 100644--- a/server/model/openai_models.go+++ b/server/model/openai_models.go@@ -6,12 +6,15 @@ import ("github.com/sashabaranov/go-openai")-var PlannerModel = "gpt-4-1106-preview" //openai.GPT4-var PlanSummaryModel = PlannerModel-var BuilderModel = PlannerModel-var ShortSummaryModel = openai.GPT3Dot5Turbo-var NameModel = openai.GPT3Dot5Turbo-var CommitMsgModel = openai.GPT3Dot5Turbo+const strongModel = openai.GPT4TurboPreview+const weakModel = openai.GPT3Dot5Turbo1106++var PlannerModel = strongModel+var PlanSummaryModel = strongModel+var BuilderModel = strongModel //openai.GPT4+var ShortSummaryModel = weakModel+var NameModel = weakModel+var CommitMsgModel = weakModelfunc init() {if os.Getenv("PLANNER_MODEL") != "" {diff --git a/server/model/prompts/create.go b/server/model/prompts/create.goindex 7c03ec10..e7cfdb72 100644--- a/server/model/prompts/create.go+++ b/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.+ 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 the user does have a task, create a plan for the task based on user-provided context using the following steps:@@ -33,9 +33,9 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context- Explicitly say "Let's break up this task."- Divide the task into smaller subtasks and list them in a numbered list. Stop there.- Always precede code blocks the file path as described above in 2a. Code must *always* be labelled with the path.+ Always precede code blocks in a plan with the file path as described above in 2a. Code must *always* be labelled with the path.- Every file you reference should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/utils.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/utils.go'.+ Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/utils.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/utils.go'.For code in markdown blocks, always include the language name after the opening triple backticks.@@ -45,12 +45,18 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextIn code blocks, include the *minimum amount of code* necessary to describe the suggested changes. Include only lines that are changing and and lines that make it clear where the change should be applied. You can use comments like "// rest of the function..." or "// rest of the file..." to help make it clear where changes should be applied. You *must not* include large sections of the original file unless it helps make the suggested changes clear.+ Don't try to do too much in a single response. The code you include in file blocks will be parsed into replacements by an AI, and then applied to the file. If you include too much code, it may not be parsed correctly or the changes may be difficult to apply.++ If plan requires a number of small changes, then multiple changes can be included single response, but they should be broken up into separate file blocks.++ For changes that are larger or more complex, only include one change per response.+At the end of a plan, you can suggest additional iterations to make the plan better. You can also ask the user to load more files or information into context if it would help you make a better plan.` +"\n```\n\n" +"User-provided context:"var CreateSysMsgNumTokens = shared.GetNumTokens(SysCreate)-const PromptWrapperFormatStr = "The user's latest prompt:\n```\n%s\n```\n\n Please respond according to the 'Your instructions' section above. Remember to precede code blocks with the file path *exactly* as described in 2a. Do not use any other formatting for file paths."+const PromptWrapperFormatStr = "The user's latest prompt:\n```\n%s\n```\n\n Please respond according to the 'Your instructions' section above. If you're making a plan, remember to precede code blocks with the file path *exactly* as described in 2a, and do not use any other formatting for file paths."var PromptWrapperTokens = shared.GetNumTokens(fmt.Sprintf(PromptWrapperFormatStr, ""))diff --git a/server/model/prompts/replace.go b/server/model/prompts/replace.goindex 08e23ae2..98fc058d 100644--- a/server/model/prompts/replace.go+++ b/server/model/prompts/replace.go@@ -1,6 +1,7 @@package promptsimport (+ "encoding/json""fmt""github.com/plandex/plandex/shared"@@ -11,13 +12,23 @@ import (const SysReplace = `[YOUR INSTRUCTIONS]-You are an AI replacer. You apply changes from a plan to a given code file using the 'writeReplacements' function.+You are an AI replacer. You apply changes from a plan to a given code file using the 'writeReplacements' function. You call 'writeReplacements' with a valid JSON array of replacements.-Call 'writeReplacements' with a list of replacements to apply to the file. Each replacement is an object with two properties: 'old' and 'new'. 'old' is the old text to replace, and 'new' is the new text to replace it with. You can include as many replacements as you want. You must include at least one replacement.-- The 'new' text must include the full text of the replacement without any placeholders or references to the original file.-- The 'old' text *ABSOLUTELY MUST BE AN EXACT SUBSTRING* of the current state of the file.-- The 'old' text must not overlap with any other 'old' text in the list of replacements.-- BE COMPLETELY SURE that replacements are inserted logically at the correct locations in the file and do not break any syntax or logic rules of the programming language.+Each replacement is an object with two properties: 'old' and 'new'. 'old' is the *exact* old text to replace, and 'new' is the new text to replace it with.++Use your judgment on how to logically apply the changes from the plan in a series of replacements. Use both the code and the plan description to determine the correct order of replacements. BE COMPLETELY SURE that replacements are inserted logically at the correct locations in the file and do not break any syntax or logic rules of the programming language.++Lean toward using fewer replacements. If you can apply all the changes in a single replacement, and that replacement isn't very long, do that. If you need to use multiple replacements, that's fine too, but try to use as few as possible.++DO NOT INCLUDE any sections that are just comments, placeholders, references to the original file, or TODOs that are not yet implemented. Only include actual changes that move the plan forward and are ready to be applied to the file.++These replacements will be applied automatically by a program to the file exactly as written, so the 'old' text must be an EXACT SUBSTRING of the current state of the file. Pay special attention to any special characters in the strings, extra spaces, or anything else that might cause 'old' not to be an exact substring.++The 'old' text should be unique and unambiguous in the current file. It must not overlap with any other 'old' text in the list of replacements. Make the 'old' text as short as it can be while still being unique and unambiguous. If the 'old' text can be a single line, it should be. If it must be multiple lines, it should be as few lines as possible.++The 'new' text must include the full text of the replacement without any placeholders or references to the original file. DO NOT INCLUDE text like "// ... existing code", "// ... rest of the file", or other equivalents with different wording/formatting/syntax in the 'new' text. Only include the actual code that should be inserted.++You MUST call only 'writeReplacements'--don't call any other function or produce any other output.Replacement examples below. Note: >>> and <<< indicate the start and end of an example response.@@ -128,7 +139,7 @@ func main() {fmt.Println("Hello, world!")fmt.Println("I love you!")}-` + "```" + `+` + "```" + `<<<Then you would call the 'writeReplacements' function like this:@@ -161,7 +172,7 @@ var ReplaceFn = openai.FunctionDefinition{},"new": {Type: jsonschema.String,- Description: "The new text to replace it with. Must be an exact substring of the suggested changes from the plan in the previous response.",+ Description: "The new text to replace it with from the changes suggested in the previous response.",},},Required: []string{"old", "new"},@@ -174,17 +185,23 @@ var ReplaceFn = openai.FunctionDefinition{func GetReplacePrompt(filePath string) string {return fmt.Sprintf(`- Based on your instructions, apply the changes from the plan to %s. Call the 'writeReplacements' function with a JSON array of replacements to apply to the file from your previous response. Each replacement is an object with two properties: 'old' and 'new'. 'old' is the old text to replace, and 'new' is the new text to replace it with. The 'old' text MUST be an exact substring of the current state of the file. The 'new' text MUST be an exact substring of the changes from the plan in the previous response. You MUST call only the 'writeReplacements'--don't call any other function or produce any other output.- `, filePath)+ Based on your instructions, apply the changes from the plan to %s. Call the 'writeReplacements' function with a JSON array of replacements to apply to the file from your previous response.`, filePath)}-func GetCorrectReplacementPrompt(failedReplacements map[int]*shared.Replacement) string {+func GetCorrectReplacementPrompt(failedReplacements map[int]*shared.Replacement, currentState string) (string, error) {msg := "There were errors with the replacements you suggested."- for index, failedReplacement := range failedReplacements {- msg += fmt.Sprintf("\n\nError in replacement at index %d:", index)- msg += fmt.Sprintf("\n- The string '%s' (which you set for the 'old' key) was not found in the file.", failedReplacement.Old)+ for i, failedReplacement := range failedReplacements {++ bytes, err := json.Marshal(failedReplacement)+ if err != nil {+ return "", fmt.Errorf("failed to marshal replacement: %w", err)+ }++ msg += fmt.Sprintf("\n- The replacement at index %d was invalid. The replacement you suggested was:\n\n```%s```\n\n", i, string(bytes))++ msg += fmt.Sprintf("\n- The string `%s` (which you set for the 'old' key of this replacement) was not found in the current state of the file.", failedReplacement.Old)}- msg += "\n\nPlease review these errors and try again to call the 'writeReplacements' function with corrected replacements. Pay special attention to any special characters in the strings, extra spaces, or anything else that might cause the strings to not match exactly."+ msg += "\n\nPlease review these errors and try again to call the 'writeReplacements' function with corrected replacements. Pay special attention to any special characters in the strings, extra spaces, or anything else that might cause the strings to not match exactly. You MUST call 'writeReplacements' with an updated list of replacements. Don't call any other function, produce any other output, or call 'writeReplacements' with the same list of replacements as before--it must be called with an updated list of replacements to fix the errors."- return msg+ return msg, nil}diff --git a/server/model/proposal/build.go b/server/model/proposal/build.goindex 1aac9c6d..6512adfe 100644--- a/server/model/proposal/build.go+++ b/server/model/proposal/build.go@@ -18,7 +18,7 @@ import ("github.com/sashabaranov/go-openai")-const MAX_RETRIES = 5+const MAX_RETRIES = 3type buildPlanParams struct {ProposalId string@@ -116,8 +116,8 @@ func buildPlan(params buildPlanParams) error {onStream("", err)}- var buildFile func(filePath string, numRetry int, failedReplacements map[int]*shared.Replacement)- buildFile = func(filePath string, numRetry int, failedReplacements map[int]*shared.Replacement) {+ var buildFile func(filePath string, numRetry int, replacements []*shared.Replacement, failedReplacements map[int]*shared.Replacement)+ buildFile = func(filePath string, numRetry int, replacements []*shared.Replacement, failedReplacements map[int]*shared.Replacement) {fmt.Printf("Building file %s, numRetry: %d\n", filePath, numRetry)// get relevant file context (if any)@@ -167,19 +167,16 @@ func buildPlan(params buildPlanParams) error {fmt.Println("Getting file from model: " + filePath)// fmt.Println("File context:", fileContext)- msg := prompts.SysReplace-+ replacePrompt := prompts.GetReplacePrompt(filePath)if currentState != "" {- fmt.Println("Adding current state to message")- msg += "\n\n" + fmt.Sprintf("\nCurrent state of %s:\n```\n%s\n```", filePath, currentState)- // fmt.Println("Message:")- // fmt.Println(msg)+ fmt.Println("Adding current state before replace prompt")+ replacePrompt = fmt.Sprintf("\nCurrent state of %s:\n```\n%s\n```", filePath, currentState) + "\n\n" + replacePrompt}fileMessages := []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,- Content: msg,+ Content: prompts.SysReplace,}, {Role: openai.ChatMessageRoleUser,Content: proposal.Request.Prompt,@@ -189,14 +186,20 @@ func buildPlan(params buildPlanParams) error {},{Role: openai.ChatMessageRoleUser,- Content: prompts.GetReplacePrompt(filePath),+ Content: replacePrompt,},}- if numRetry > 0 && failedReplacements != nil {- bytes, err := json.Marshal(failedReplacements)+ if numRetry > 0 && replacements != nil && failedReplacements != nil {+ bytes, err := json.Marshal(replacements)+ if err != nil {+ onBuildFileError(filePath, fmt.Errorf("error marshalling replacements: %v", err))+ return+ }++ correctReplacementPrompt, err := prompts.GetCorrectReplacementPrompt(failedReplacements, currentState)if err != nil {- onBuildFileError(filePath, fmt.Errorf("error marshalling failed replacements: %v", err))+ onBuildFileError(filePath, fmt.Errorf("error getting correct replacement prompt: %v", err))return}@@ -208,15 +211,15 @@ func buildPlan(params buildPlanParams) error {openai.ChatCompletionMessage{Role: openai.ChatMessageRoleUser,- Content: prompts.GetCorrectReplacementPrompt(failedReplacements),+ Content: correctReplacementPrompt,})}fmt.Println("Calling model for file: " + filePath)- // for _, msg := range fileMessages {- // fmt.Printf("%s: %s\n", msg.Role, msg.Content)- // }+ for _, msg := range fileMessages {+ fmt.Printf("%s: %s\n", msg.Role, msg.Content)+ }modelReq := openai.ChatCompletionRequest{Model: model.BuilderModel,@@ -234,7 +237,7 @@ func buildPlan(params buildPlanParams) error {onBuildFileError(filePath, fmt.Errorf("failed to create plan file stream for path '%s' after %d retries: %v", filePath, numRetry, err))} else {fmt.Println("Retrying build plan for file: " + filePath)- buildFile(filePath, numRetry+1, failedReplacements)+ buildFile(filePath, numRetry+1, replacements, failedReplacements)if err != nil {onBuildFileError(filePath, fmt.Errorf("failed to retry build plan for file '%s': %v", filePath, err))}@@ -249,7 +252,7 @@ func buildPlan(params buildPlanParams) error {timer := time.NewTimer(model.OPENAI_STREAM_CHUNK_TIMEOUT)defer timer.Stop()- handleErrorRetry := func(maxRetryErr error, shouldSleep bool, failed map[int]*shared.Replacement) {+ handleErrorRetry := func(maxRetryErr error, shouldSleep bool, rep []*shared.Replacement, failed map[int]*shared.Replacement) {fmt.Printf("Error for file %s: %v\n", filePath, maxRetryErr)if numRetry >= MAX_RETRIES {@@ -258,7 +261,7 @@ func buildPlan(params buildPlanParams) error {if shouldSleep {time.Sleep(1 * time.Second * time.Duration(math.Pow(float64(numRetry+1), 2)))}- buildFile(filePath, numRetry+1, failed)+ buildFile(filePath, numRetry+1, rep, failed)if err != nil {onBuildFileError(filePath, fmt.Errorf("failed to retry build plan for file '%s': %v", filePath, err))}@@ -276,6 +279,7 @@ func buildPlan(params buildPlanParams) error {handleErrorRetry(fmt.Errorf("stream timeout due to inactivity for file '%s' after %d retries", filePath, numRetry),true,+ replacements,failedReplacements,)return@@ -296,13 +300,14 @@ func buildPlan(params buildPlanParams) error {handleErrorRetry(fmt.Errorf("stream error for file '%s' after %d retries: %v", filePath, numRetry, err),true,+ replacements,failedReplacements,)return}if len(response.Choices) == 0 {- handleErrorRetry(fmt.Errorf("stream error: no choices"), true, failedReplacements)+ handleErrorRetry(fmt.Errorf("stream error: no choices"), true, replacements, failedReplacements)return}@@ -313,6 +318,7 @@ func buildPlan(params buildPlanParams) error {handleErrorRetry(fmt.Errorf("stream finished without a function call. Reason: %s, File: %s", choice.FinishReason, filePath),false,+ replacements,failedReplacements,)return@@ -330,6 +336,7 @@ func buildPlan(params buildPlanParams) error {handleErrorRetry(fmt.Errorf("stream finished before replacements parsed. File: %s", filePath),true,+ replacements,failedReplacements,)return@@ -380,6 +387,7 @@ func buildPlan(params buildPlanParams) error {handleErrorRetry(fmt.Errorf("failed to apply replacements to file '%s' after %d retries", filePath, numRetry),false,+ replacements.Replacements,failed,)return@@ -408,7 +416,7 @@ func buildPlan(params buildPlanParams) error {}for _, filePath := range proposal.PlanDescription.Files {- go buildFile(filePath, 0, nil)+ go buildFile(filePath, 0, nil, nil)}return nildiff --git a/server/model/proposal/create.go b/server/model/proposal/create.goindex e46383af..9098000a 100644--- a/server/model/proposal/create.go+++ b/server/model/proposal/create.go@@ -93,7 +93,8 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorfmt.Printf("Conversation tokens: %d\n", conversationTokens)var summary *shared.ConversationSummary- if (totalTokens + conversationTokens) > shared.MaxTokens {+ if (totalTokens+conversationTokens) > shared.MaxTokens ||+ conversationTokens > shared.MaxConvoTokens {fmt.Println("Token limit exceeded. Attempting to reduce via conversation summary.")// token limit exceeded after adding conversation@@ -116,7 +117,8 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorfmt.Printf("Updated conversation tokens: %d\n", updatedConversationTokens)fmt.Printf("Saved tokens: %d\n", savedTokens)- if (totalTokens + updatedConversationTokens) <= shared.MaxTokens {+ if updatedConversationTokens <= shared.MaxConvoTokens &&+ (totalTokens+updatedConversationTokens) <= shared.MaxTokens {fmt.Printf("Summarizing up to %s | saving %d tokens\n", s.LastMessageTimestamp, savedTokens)summary = &sbreakdiff --git a/shared/tokens.go b/shared/tokens.goindex b15481e3..cbbc2720 100644--- a/shared/tokens.go+++ b/shared/tokens.go@@ -7,8 +7,9 @@ import ("github.com/pkoukk/tiktoken-go")-const MaxTokens int = 16000 // leave room for the model ouput-const MaxContextTokens int = 15000 // leave room for the conversation history+var MaxTokens int = 120000+var MaxContextTokens int = 50000+var MaxConvoTokens int = 20000func GetNumTokens(text string) (numTokens int) {tkm, err := tiktoken.EncodingForModel("gpt-4")