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
show log timestamps in local time, improvements to plan auto-continue check
Dane Schneidera5db2c38d5a4
diff --git a/app/cli/cmd/log.go b/app/cli/cmd/log.goindex 4a45b27d..4cf2ca20 100644--- a/app/cli/cmd/log.go+++ b/app/cli/cmd/log.go@@ -2,6 +2,7 @@ package cmdimport ("fmt"+ "log""plandex/api""plandex/auth""plandex/lib"@@ -50,13 +51,14 @@ func runLog(cmd *cobra.Command, args []string) {}term.PageOutput(withLocalTimestamps)+}func convertTimestampsToLocal(input string) (string, error) {t := time.Now()zone, _ := t.Zone()- parseFmt := "Mon Jan 2, 2006 | 3:04:05pm UTC"+ 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`)// Function to convert matched timestamps assuming they are in UTC to local time.@@ -67,8 +69,16 @@ func convertTimestampsToLocal(input string) (string, error) {return match}+ log.Println("t: ", t)+localDt := t.Local()++ log.Println("localDt: ", localDt)+formattedTs := localDt.Format("Mon Jan 2, 2006 | 3:04:05pm")++ log.Println("formattedTs: ", formattedTs)+if localDt.Day() == time.Now().Day() {formattedTs = localDt.Format("Today | 3:04:05pm")} else if localDt.Day() == time.Now().AddDate(0, 0, -1).Day() {diff --git a/app/cli/term/errors.go b/app/cli/term/errors.goindex eb84e66b..21381410 100644--- a/app/cli/term/errors.go+++ b/app/cli/term/errors.go@@ -8,5 +8,5 @@ import ()func OutputNoApiKeyMsg() {- fmt.Fprintln(os.Stderr, color.New(color.Bold, color.FgHiRed).Sprintln("\nπ¨ OPENAI_API_KEY environment variable is not set.")+color.New().Sprintln("\nSet it with:\n\nexport OPENAI_API_KEY=...\n\nThen try again.\n\nπ If you don't have an OpenAI account, sign up here β https://platform.openai.com/signup\n\nπ Generate an api key here β https://platform.openai.com/api-keys"))+ fmt.Fprintln(os.Stderr, color.New(color.Bold, color.FgHiRed).Sprintln("\nπ¨ OPENAI_API_KEY environment variable is not set.")+color.New().Sprintln("\nSet it with:\n\nexport OPENAI_API_KEY=your-api-key\n\nThen try again.\n\nπ If you don't have an OpenAI account, sign up here β https://platform.openai.com/signup\n\nπ Generate an api key here β https://platform.openai.com/api-keys"))}diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.goindex c8acc466..2db91588 100644--- a/app/server/model/plan/exec_status.go+++ b/app/server/model/plan/exec_status.go@@ -3,14 +3,31 @@ package planimport ("context""encoding/json"- "fmt"+ "log""plandex-server/model""plandex-server/model/prompts"+ "strings"+ "github.com/davecgh/go-spew/spew""github.com/sashabaranov/go-openai")func ExecStatusShouldContinue(client *openai.Client, message string, ctx context.Context) (bool, error) {+ // First try to determine if the plan should continue based on the last paragraph without calling the model+ paragraphs := strings.Split(message, "\n\n")+ lastParagraph := paragraphs[len(paragraphs)-1]+ if lastParagraph != "" {+ if strings.Contains(lastParagraph, "All tasks have been completed") ||+ strings.Contains(lastParagraph, "all tasks have been completed") ||+ strings.Contains(lastParagraph, "plan cannot be continued") {+ return false, nil+ }++ if strings.Index(lastParagraph, "Next, ") < 3 {+ return true, nil+ }+ }+messages := []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,@@ -29,8 +46,11 @@ func ExecStatusShouldContinue(client *openai.Client, message string, ctx context)if err != nil {- fmt.Printf("Error during plan exec status check model call: %v\n", err)- return false, err+ log.Printf("Error during plan exec status check model call: %v\n", err)+ // return false, fmt.Errorf("error during plan exec status check model call: %v", err)++ // Instead of erroring out, just don't continue the plan+ return false, nil}var strRes string@@ -48,14 +68,23 @@ func ExecStatusShouldContinue(client *openai.Client, message string, ctx context}if strRes == "" {- fmt.Println("No shouldAutoContinue function call found in response")- return false, fmt.Errorf("no shouldAutoContinue function call found in response")+ log.Println("No shouldAutoContinue function call found in response")+ spew.Dump(resp)++ // return false, fmt.Errorf("no shouldAutoContinue function call found in response")++ // Instead of erroring out, just don't continue the plan+ return false, nil}err = json.Unmarshal([]byte(strRes), &res)if err != nil {- fmt.Printf("Error unmarshalling plan exec status response: %v\n", err)- return false, err+ log.Printf("Error unmarshalling plan exec status response: %v\n", err)++ // return false, fmt.Errorf("error unmarshalling plan exec status response: %v", err)++ // Instead of erroring out, just don't continue the plan+ return false, nil}return res.ShouldContinue, nildiff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.goindex 0509fbb4..021b08c2 100644--- a/app/server/model/prompts/create.go+++ b/app/server/model/prompts/create.go@@ -57,17 +57,20 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextAt the end of your response, you can suggest additional iterations to make the plan better. You can also ask the user to load more files into context or give you more information if it would help you make a better plan.- At the *very* end of your response, you *must* decide whether the plan is completed and if not, whether it should be automatically continued.+ At the *very* end of your response, in a final, separate paragraph, you *must* decide whether the plan is completed and if not, whether it should be automatically continued.- If all the steps in a plan are completed (even if there is only one step), you must explictly say "All tasks have been completed."Otherwise:- If there is a clear next step that definitely needs to be done to finish the plan (and has not already been completed), output a sentence starting with "Next, " and then give a brief description of the next step.- - If there is no clear next step, or the user needs to take some action before you can continue, finish with a brief description of what the user needs to do for the plan to proceed.+ - If there is no clear next step, or the user needs to take some action before you can continue, explicitly say "The plan cannot be continued." Then finish with a brief description of what the user needs to do for the plan to proceed.+ You must not output any other text after this final paragraph. It *must* be the last thing in your response, and it *must* begin with one of the three options above ("All tasks have been completed.", "Next, ", or "The plan cannot be continued.").You should lean toward considering the plan complete if all the subtasks are completed to a decent standard. Even if there are additional steps that *could* be taken, if you have completed the tasks you were asked to do, you should consider the plan complete. Be cautious about suggesting additional steps (with the "Next, " syntax) that are not strictly necessary to complete the task at hand. Only suggest additional steps if the next step is clear and has already been well established in the conversation.Don't consider the user verifying or testing the code as a next step. If all that's left is for the user to verify or test the code, consider the plan complete. Unless *you* can make clear progress on the plan *yourself* without the user's input, the plan should be considered complete.Remember that when you suggest a next step, the plan will continue automatically. Being over-eager to continue can cause infinite loops and other problems.++ Remember not to ask the user to do anything that you can do yourself, or anything that isn't strictly necessary for completing the plan to a decent standard. It's preferable to finish the plan with either the "All tasks have been completed." option or the "Next, " option if possible. Only if the plan clearly isn't completed and has no clear next step that you can do yourself should you use the "The plan cannot be continued." option.Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context. For example, if you are working on a plan that has been broken up into subtasks, and you've reached the point of implementing a particular subtask, first consider whether the subtask is still necessary looking at the files in context. If it has already been implemented or is no longer necessary, say so, revise the plan if needed, and move on. Otherwise, implement the subtask.` +diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.goindex 117ebb2a..1ca4587a 100644--- a/app/server/model/prompts/exec_status.go+++ b/app/server/model/prompts/exec_status.go@@ -7,24 +7,19 @@ import (const SysExecStatusShouldContinue = `You are tasked with evaluating a response generated by another AI (AI 1).-Here is the prompt of AI 1:--[START OF PROMPT OF AI 1]-` + SysCreate + `[END OF PROMPT OF AI 1]-Your goal is to determine whether the plan created by AI 1 should automatically continue or if it is considered complete. To do this, you need to analyze the latest message of the plan from AI 1 carefully and decide based on the following criteria:-Completion of Tasks: Assess whether AI 1 has indicated that all tasks and subtasks within the plan have been completed. AI 1 should explicitly state "All tasks have been completed" if this is the case. If such a statement is present, the plan is considered complete.+Assess whether AI 1 has indicated that all tasks and subtasks within the plan have been completed. AI 1 should explicitly state "All tasks have been completed" if this is the case. If such a statement is present, the plan is considered complete and should not continue.-Next Steps Identified: If AI 1 has outlined a clear next step necessary to finish the plan but has not executed it, the plan should likely continue. Look for sentences starting with "Next, " followed by a brief description of what should be done. This suggests that AI 1 has identified a subsequent action that needs to be taken, implying the plan is not yet complete.+If AI 1 has concluded with a statement that indicates either the user needs to take specific actions before the plan can proceed, or that the plan can't automatically continue for any other reason. Look for the sentence "The plan isn't complete, but it can't be continued." followed by a description of what the user needs to or the reason why the plan cannot continue. In this case, the plan should not contineu.-User Actions Required: Determine if AI 1 has concluded with a statement that indicates the user needs to take specific actions before the plan can proceed. This might involve loading more files into the context, providing additional information, or implementing suggestions. If AI 1 specifies actions for the user, the plan's automatic continuation depends on those user actions being completed.+If AI 1 has outlined a clear next step necessary to finish the plan but has not executed it, the plan should continue. Look for a sentence at the end of the response starting with "Next, " followed by a brief description of what should be done. In this place, the plan should continue.-Avoidance of Infinite Loops: Be cautious of suggesting the plan continue if the next steps are not clear or if continuation could lead to repetitive or circular tasking. Ensuring that the plan moves forward constructively without causing confusion or redundancy is crucial.+You *must* call the shouldAutoContinue function with a JSON object containing the key 'shouldContinue'.-Based on your analysis, you will call the shouldAutoContinue function with a JSON object containing the key 'shouldContinue'. Set 'shouldContinue' to true if the plan should automatically continue based on the outlined criteria or false if the plan is complete or cannot proceed without user intervention.+Set 'shouldContinue' to true if the plan should automatically continue based on the outlined criteria or false otherwise.-You must always call 'shouldAutoContinue' in your response. Don't call any other function.`+You must always call 'shouldAutoContinue'. Don't call any other function.`func GetExecStatusShouldContinue(message string) string {return SysExecStatusShouldContinue + "\n\n**Here is the latest message of the plan from AI 1:**\n" + message