Skip to content

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

fixes for auto-verify-and-fix step, prompts still need work

Dane Schneider3e31f372aab3
diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.go
index 8b51fbbc..6cf3a3cc 100644
--- a/app/server/model/plan/build_finish.go
+++ b/app/server/model/plan/build_finish.go
@@ -6,6 +6,7 @@ import (
"net/http"
"plandex-server/db"
"plandex-server/types"
+ "strings"
"github.com/plandex/plandex/shared"
)
@@ -157,6 +158,11 @@ func (state *activeBuildStreamFileState) onFinishBuild() {
err = db.GitAddAndCommit(currentOrgId, planId, branch, currentPlan.PendingChangesSummaryForBuild())
if err != nil {
+ if strings.Contains(err.Error(), "nothing to commit") {
+ log.Println("Nothing to commit")
+ return nil
+ }
+
log.Printf("Error committing plan build: %v\n", err)
ap.StreamDoneCh <- &shared.ApiError{
Type: shared.ApiErrorTypeOther,
@@ -202,7 +208,6 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanF
filePath := fileState.filePath
- buildFinished := false
log.Println("onFinishBuildFile: " + filePath)
if planRes != nil {
@@ -266,66 +271,61 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanF
activeBuild.Success = true
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.BuiltFiles[filePath] = true
- if ap.BuildFinished() {
- buildFinished = true
+ // if more builds are queued, start the next one regardless of whether this is a verification build or not, then return
+ if !activePlan.PathQueueEmpty(filePath) {
+ log.Printf("Processing next build for file %s\n", filePath)
+ activePlan := GetActivePlan(planId, branch)
+ if activePlan == nil {
+ log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)
+ return
+ }
+ queue := activePlan.BuildQueuesByPath[filePath]
+ var nextBuild *types.ActiveBuild
+ for _, build := range queue {
+ if !build.BuildFinished() {
+ nextBuild = build
+ break
+ }
}
- })
- log.Printf("Finished building file %s\n", filePath)
+ if nextBuild != nil {
+ log.Println("Calling execPlanBuild for next build in queue")
+ go fileState.execPlanBuild(nextBuild)
+ }
+ return
+ }
+
+ // otherwise:
+ // if this is a verification build, check if the build is finished and call onFinishBuild if it is
+ // if this is not a verification build, trigger the verification build
+ if activeBuild.IsVerification {
+ buildFinished := false
+
+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
+ ap.BuiltFiles[filePath] = true
+ ap.IsBuildingByPath[filePath] = false
+ if ap.BuildFinished() {
+ buildFinished = true
+ }
+ })
- if buildFinished {
- if activeBuild.IsVerification {
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.IsBuildingByPath[filePath] = false
- })
+ log.Printf("Finished building file %s\n", filePath)
+
+ if buildFinished {
log.Println("Finished building plan, calling onFinishBuild")
fileState.onFinishBuild()
- } else {
- log.Println("queuing verification build")
- log.Println("preBuildState:\n", fileState.preBuildState)
- log.Println("updated:\n", fileState.updated)
-
-go fileState.execPlanBuild(&types.ActiveBuild{
- ReplyId: activeBuild.ReplyId,
- FileDescription: activeBuild.FileDescription,
- FileContent: activeBuild.FileContent,
- Path: activeBuild.Path,
- Idx: activeBuild.Idx,
- IsVerification: true,
- ToVerifyPreBuildState: fileState.preBuildState,
- ToVerifyUpdatedState: fileState.updated,
-})
}
} else {
- if activePlan.PathFinished(filePath) {
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.IsBuildingByPath[filePath] = false
- })
- log.Printf("File %s finished, but not all builds finished\n", filePath)
- } else {
- log.Printf("Processing next build for file %s\n", filePath)
- activePlan := GetActivePlan(planId, branch)
- if activePlan == nil {
- log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)
- return
- }
- queue := activePlan.BuildQueuesByPath[filePath]
- var nextBuild *types.ActiveBuild
- for _, build := range queue {
- if !build.BuildFinished() {
- nextBuild = build
- break
- }
- }
-
- if nextBuild != nil {
- log.Println("Calling execPlanBuild for next build in queue")
- go fileState.execPlanBuild(nextBuild)
- }
- return
- }
+ go fileState.execPlanBuild(&types.ActiveBuild{
+ ReplyId: activeBuild.ReplyId,
+ FileDescription: activeBuild.FileDescription,
+ FileContent: activeBuild.FileContent,
+ Path: activeBuild.Path,
+ Idx: activeBuild.Idx,
+ IsVerification: true,
+ ToVerifyPreBuildState: fileState.preBuildState,
+ ToVerifyUpdatedState: fileState.updated,
+ })
}
}
@@ -376,4 +376,3 @@ func (fileState *activeBuildStreamFileState) onBuildFileError(err error) {
log.Printf("Error clearing uncommitted changes: %v\n", err)
}
}
-
diff --git a/app/server/model/plan/build_verify.go b/app/server/model/plan/build_verify.go
index 1b3436e4..6dad012a 100644
--- a/app/server/model/plan/build_verify.go
+++ b/app/server/model/plan/build_verify.go
@@ -28,13 +28,12 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {
log.Printf("verifyFileBuild - Verifying file %s\n", filePath)
- log.Println("verifyFileBuild - Getting file from model: " + filePath)
// log.Println("File context:", fileContext)
- log.Printf("preBuildState has content: %v\n", preBuildState != "")
- log.Printf("updated has content: %v\n", updated != "")
- log.Printf("activeBuild.FileDescription has content: %v\n", activeBuild.FileDescription != "")
- log.Printf("activeBuild.FileContent has content: %v\n", activeBuild.FileContent != "")
+ // log.Printf("preBuildState has content: %v\n", preBuildState != "")
+ // log.Printf("updated has content: %v\n", updated != "")
+ // log.Printf("activeBuild.FileDescription has content: %v\n", activeBuild.FileDescription != "")
+ // log.Printf("activeBuild.FileContent has content: %v\n", activeBuild.FileContent != "")
sysPrompt := prompts.GetVerifyPrompt(preBuildState, updated, activeBuild.FileDescription, activeBuild.FileContent)
diff --git a/app/server/model/plan/build_verify_stream.go b/app/server/model/plan/build_verify_stream.go
index 7be473b2..e826cf70 100644
--- a/app/server/model/plan/build_verify_stream.go
+++ b/app/server/model/plan/build_verify_stream.go
@@ -70,7 +70,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
BuildInfo: buildInfo,
})
- log.Println("build verify - error - Plan file result:")
+ log.Println("build verify - error")
fileState.onFinishBuildFile(nil)
return
@@ -86,7 +86,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
Type: shared.StreamMessageBuildInfo,
BuildInfo: buildInfo,
})
- log.Println("build verify - no choices - Plan file result:")
+ log.Println("build verify - no choices")
fileState.onFinishBuildFile(nil)
return
}
@@ -112,7 +112,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
Type: shared.StreamMessageBuildInfo,
BuildInfo: buildInfo,
})
- log.Println("build verify - invalid json - Plan file result:")
+ log.Println("build verify - invalid json")
fileState.onFinishBuildFile(nil)
return
}
@@ -150,7 +150,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
Type: shared.StreamMessageBuildInfo,
BuildInfo: buildInfo,
})
- log.Println("build verify - streamed.IsCorrect - Plan file result:")
+ log.Println("build verify - streamed.IsCorrect")
fileState.onFinishBuildFile(nil)
} else {
log.Printf("listenStreamVerifyOutput - File %s: Streamed verify result is incorrect: %s\n", filePath, streamed.Reasoning)
@@ -168,7 +168,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
}
return
} else if len(delta.ToolCalls) == 0 {
- log.Println("listenStreamVerifyOutput - Stream chunk missing function call. Buffer:")
+ log.Println("listenStreamVerifyOutput - Stream chunk missing function call.")
// log.Println(spew.Sdump(response))
if fileState.verifyFileNumRetry > 0 {
@@ -181,7 +181,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
Type: shared.StreamMessageBuildInfo,
BuildInfo: buildInfo,
})
- log.Println("build verify - retry - Plan file result:")
+ log.Println("build verify - retry")
fileState.onFinishBuildFile(nil)
} else {
fileState.verifyRetryOrError(fmt.Errorf("listenStreamVerifyOutput - stream chunk missing function call. Reason: %s, File: %s", choice.FinishReason, filePath))
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index 1d72e30b..37c0c09d 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -12,7 +12,7 @@ import (
"github.com/sashabaranov/go-openai"
)
-func (state *activeTellStreamState) execStatusShouldContinue(prompt, message string, ctx context.Context) (bool, error) {
+func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx context.Context) (bool, error) {
settings := state.settings
clients := state.clients
config := settings.ModelPack.ExecStatus
@@ -63,12 +63,15 @@ func (state *activeTellStreamState) execStatusShouldContinue(prompt, message str
messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
- Content: prompts.GetExecStatusShouldContinue(latestSummary, prevAssistantMsg, prompt, message),
+ Content: prompts.GetExecStatusShouldContinue(latestSummary, prevAssistantMsg, state.userPrompt, message),
},
}
log.Println("Calling model to check if plan should continue")
+ log.Println("messages:")
+ log.Println(spew.Sdump(messages))
+
var responseFormat *openai.ChatCompletionResponseFormat
if config.BaseModelConfig.HasJsonResponseMode {
responseFormat = &openai.ChatCompletionResponseFormat{Type: "json_object"}
diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.go
index cf258948..7dc10973 100644
--- a/app/server/model/plan/tell_stream.go
+++ b/app/server/model/plan/tell_stream.go
@@ -56,7 +56,6 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
convo := state.convo
summaries := state.summaries
summarizedToMessageId := state.summarizedToMessageId
- promptMessage := state.promptMessage
iteration := state.iteration
missingFileResponse := state.missingFileResponse
replyId := state.replyId
@@ -262,14 +261,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
go func() {
// One of the below is nil occasionally, causing crash
log.Println("Getting exec status")
- var prompt string
- if promptMessage == nil {
- log.Println("Prompt message is nil")
- } else {
- prompt = promptMessage.Content
- }
-
- shouldContinue, err = state.execStatusShouldContinue(prompt, assistantMsg.Message, active.Ctx)
+ shouldContinue, err = state.execStatusShouldContinue(assistantMsg.Message, active.Ctx)
if err != nil {
state.onError(fmt.Errorf("failed to get exec status: %v", err), false, assistantMsg.Id, convoCommitMsg)
errCh <- err
diff --git a/app/server/model/prompts/build.go b/app/server/model/prompts/build.go
index 7fb6a613..cb26d0e3 100644
--- a/app/server/model/prompts/build.go
+++ b/app/server/model/prompts/build.go
@@ -187,6 +187,16 @@ func getFixChangesLineNumsPrompt() string {
return `
You are an AI that analyzes an incorrect updated file, the changes that should have been applied to the file, a description of the problems with the file, and a plan to fix them, and then produces a list of changes to apply to the *incorrect updated file* that will fix *ALL* the problems.
+ Problems you MUST fix include:
+ - Syntax errors
+ - Incorrectly applied changes
+ - Incorrectly removed code
+ - Incorrectly overwritten code
+ - Incorrectly duplicated code
+ - Incorrectly applied comments that reference the original code
+
+ If the updated includes references to the original code in comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods..." **any other reference to the original code, the file is incorrect. References like these must be handled by including the exact code from the original file that the comment is referencing.
+
[YOUR INSTRUCTIONS]
` + lineNumsFunctionCallPrompt + `
@@ -196,6 +206,8 @@ func getFixChangesLineNumsPrompt() string {
` + changeLineInclusionAndNewPrompt + `
+ You MUST ensure the line numbers for the 'old' property correctly remove *ALL* code that has problems and that the 'new' property correctly fixes *ALL* the problems present in the updated file. You MUST NOT miss any problems, fail to fix any problems, or introduce any new problems.
+
Example function call with all keys:
---
listChangesWithLineNums([{
@@ -283,11 +295,13 @@ func GetVerifyPrompt(preBuildState, updated, desc, changes string) string {
s := `
Based on an original file (if one exists), an AI-generated plan, and an updated file, determine whether the proposed changes were applied correctly to the updated file. Is the syntax in the updated file correct? Were the changes applied correctly or was some code from the original file removed or overwritten that should not have been? Does the updated file as a whole make sense and was it updated consistently with the intention of the plan? Were *all* comments in the proposed changes that referenced the original code correctly handled in the updated file by including the exact code from the original file that the comment was referencing? Did any code get duplicated that should not have been?
+If the updated includes references to the original code in comments like "// rest of the function..." or "# existing init code...", or "// rest of the main function..." or "// rest of your function..." or "// Existing methods...", "// Existing code..." **any other reference to the original code**, the file is incorrect. References like these must be handled by including the exact code from the original file that the comment is referencing.
+
If there is no original file, it means that a new file was created from scratch based on the AI-generated plan. In this case, the syntax in the new file must be valid and consistent with the intention of the plan. You must ensure there are no syntax errors or other clear mistakes in the new file.
Call the 'verifyOutput' function with a valid JSON object that include the 'reasoning' and 'isCorrect' keys.
-'reasoning': Succinctly explain whether the proposed changes were or were not applied correctly and whether the syntax is valid. If the changes were not applied correctly or the syntax isn't valid, briefly explain what went wrong and what needs to be done to fix the errors. If the syntax isn't valid only because the syntax wasn't valid in the original file, explain that the syntax, though incorrect, is consistent with the original file and that the changes were applied correctly.
+'reasoning': Succinctly explain whether the proposed changes were or were not applied correctly and whether the syntax is valid. If the changes were not applied correctly or the syntax isn't valid, list *EVERY* problem and what needs to be done to fix *ALL* the errors. If the syntax isn't valid only because the syntax wasn't valid in the original file, explain that the syntax, though incorrect, is consistent with the original file and that the changes were applied correctly.
'isCorrect': A boolean that indicates whether the proposed changes were applied correctly. If the proposed changes were applied correctly, set 'isCorrect' to true. If the proposed changes were not applied correctly, set 'isCorrect' to false.
`
diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.go
index 42d38b69..f8177e28 100644
--- a/app/server/model/prompts/create.go
+++ b/app/server/model/prompts/create.go
@@ -29,6 +29,20 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
- main.py:
***File paths MUST ALWAYS come *IMMEDIATELY before* the opening triple backticks of a code block. They should *not* be included in the code block itself. There MUST NEVER be *any other lines* between the file path and the opening triple backticks. Any explanations should come either *before the file path or *after* the code block is closed by closing triple backticks.*
***You *must not* include **any other text** in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. Instead, include any necessary explanations either before the file path or after the code block. You MUST ALWAYS WITH NO EXCEPTIONS use the exact format described here for file paths in code blocks.
+ ***Do NOT include the file path again within the triple backticks, inside the code block itself. The file path must be included *only* in the file block label *preceding* the opening triple backticks.***
+
+ Labelled code block examples:
+
+ - src/game.h:
+ ` + "```c" + `
+
+ #ifndef GAME_LOGIC_H
+ #define GAME_LOGIC_H
+
+ void updateGameLogic();
+
+ #endif
+ ` + "```" + `
b. If not:
- Explicitly say "Let's break up this task."
- Divide the task into smaller subtasks and list them in a numbered list. Stop there.
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index 153ce8e0..ce38bf8e 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -175,14 +175,14 @@ func (ap *ActivePlan) ResetModelCtx() {
func (ap *ActivePlan) BuildFinished() bool {
for path := range ap.BuildQueuesByPath {
- if !ap.PathFinished(path) {
+ if ap.IsBuildingByPath[path] || !ap.PathQueueEmpty(path) {
return false
}
}
return true
}
-func (ap *ActivePlan) PathFinished(path string) bool {
+func (ap *ActivePlan) PathQueueEmpty(path string) bool {
for _, build := range ap.BuildQueuesByPath[path] {
if !build.BuildFinished() {
return false