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
working on auto verify and fix step, but have a state bug to fix
Dane Schneidere01a5b1ca827
diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.goindex cd6d4aab..e0ecefa3 100644--- a/app/server/model/plan/build_exec.go+++ b/app/server/model/plan/build_exec.go@@ -8,6 +8,7 @@ import ("plandex-server/model/prompts""plandex-server/types"+ "github.com/davecgh/go-spew/spew""github.com/plandex/plandex/shared""github.com/sashabaranov/go-openai")@@ -160,7 +161,11 @@ func (buildState *activeBuildStreamState) execPlanBuild(activeBuild *types.Activreturn}- fileState.buildFile()+ if activeBuild.IsVerification {+ fileState.verifyFileBuild()+ } else {+ fileState.buildFile()+ }}func (fileState *activeBuildStreamFileState) buildFile() {@@ -209,7 +214,7 @@ func (fileState *activeBuildStreamFileState) buildFile() {// log.Println("\n\nCurrent state:\n", currentState, "\n\n")}- fileState.currentState = currentState+ fileState.preBuildState = currentStateif currentState == "" {log.Printf("File %s not found in model context or current plan. Creating new file.\n", filePath)@@ -234,6 +239,12 @@ func (fileState *activeBuildStreamFileState) buildFile() {Path: filePath,Content: activeBuild.FileContent,}++ fileState.updated = activeBuild.FileContent++ log.Println("build exec - Plan file result:")+ spew.Dump(planRes)+fileState.onFinishBuildFile(planRes)return} else {@@ -260,7 +271,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {planId := fileState.plan.Idbranch := fileState.branchconfig := fileState.settings.ModelPack.Builder- currentState := fileState.currentState+ originalFile := fileState.preBuildStateactivePlan := GetActivePlan(planId, branch)@@ -274,7 +285,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {// log.Println("currentState:", currentState)- sysPrompt := prompts.GetBuildLineNumbersSysPrompt(filePath, currentState, activeBuild.FileDescription, activeBuild.FileContent)+ sysPrompt := prompts.GetBuildLineNumbersSysPrompt(filePath, originalFile, activeBuild.FileDescription, activeBuild.FileContent)fileMessages := []openai.ChatCompletionMessage{{diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.goindex 493a7f07..0a3b8a40 100644--- a/app/server/model/plan/build_finish.go+++ b/app/server/model/plan/build_finish.go@@ -202,63 +202,66 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFfilePath := fileState.filePath- finished := false+ buildFinished := falselog.Println("onFinishBuildFile: " + filePath)- repoLockId, err := db.LockRepo(- db.LockRepoParams{- OrgId: currentOrgId,- UserId: currentUserId,- PlanId: planId,- Branch: branch,- PlanBuildId: build.Id,- Scope: db.LockScopeWrite,- Ctx: activePlan.Ctx,- CancelFn: activePlan.CancelFn,- },- )- if err != nil {- log.Printf("Error locking repo for build file: %v\n", err)- activePlan.StreamDoneCh <- &shared.ApiError{- Type: shared.ApiErrorTypeOther,- Status: http.StatusInternalServerError,- Msg: "Error locking repo for build file: " + err.Error(),+ if planRes != nil {++ repoLockId, err := db.LockRepo(+ db.LockRepoParams{+ OrgId: currentOrgId,+ UserId: currentUserId,+ PlanId: planId,+ Branch: branch,+ PlanBuildId: build.Id,+ Scope: db.LockScopeWrite,+ Ctx: activePlan.Ctx,+ CancelFn: activePlan.CancelFn,+ },+ )+ if err != nil {+ log.Printf("Error locking repo for build file: %v\n", err)+ activePlan.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error locking repo for build file: " + err.Error(),+ }+ return}- return- }- err = func() error {- var err error- defer func() {- if err != nil {- log.Printf("Error: %v\n", err)- err = db.GitClearUncommittedChanges(currentOrgId, planId)+ err = func() error {+ var err error+ defer func() {if err != nil {- log.Printf("Error clearing uncommitted changes: %v\n", err)+ log.Printf("Error: %v\n", err)+ err = db.GitClearUncommittedChanges(currentOrgId, planId)+ if err != nil {+ log.Printf("Error clearing uncommitted changes: %v\n", err)+ }}- }- err := db.UnlockRepo(repoLockId)+ err := db.UnlockRepo(repoLockId)+ if err != nil {+ log.Printf("Error unlocking repo: %v\n", err)+ }+ }()++ err = db.StorePlanResult(planRes)if err != nil {- log.Printf("Error unlocking repo: %v\n", err)+ log.Printf("Error storing plan result: %v\n", err)+ activePlan.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error storing plan result: " + err.Error(),+ }+ return err}+ return nil}()- err = db.StorePlanResult(planRes)if err != nil {- log.Printf("Error storing plan result: %v\n", err)- activePlan.StreamDoneCh <- &shared.ApiError{- Type: shared.ApiErrorTypeOther,- Status: http.StatusInternalServerError,- Msg: "Error storing plan result: " + err.Error(),- }- return err+ return}- return nil- }()-- if err != nil {- return}activeBuild.Success = true@@ -266,18 +269,31 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFUpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {ap.BuiltFiles[filePath] = trueif ap.BuildFinished() {- finished = true+ buildFinished = true}})log.Printf("Finished building file %s\n", filePath)- if finished {- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {- ap.IsBuildingByPath[filePath] = false- })- log.Println("Finished building plan, calling onFinishBuild")- fileState.onFinishBuild()+ if buildFinished {+ if activeBuild.IsVerification {+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {+ ap.IsBuildingByPath[filePath] = false+ })+ log.Println("Finished building plan, calling onFinishBuild")+ fileState.onFinishBuild()+ } else {+ 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) {diff --git a/app/server/model/plan/build_fix.go b/app/server/model/plan/build_fix.goindex 0d3b515d..40b071bb 100644--- a/app/server/model/plan/build_fix.go+++ b/app/server/model/plan/build_fix.go@@ -34,8 +34,6 @@ func (fileState *activeBuildStreamFileState) fixFileLineNums() {log.Println("fixFileLineNums - getting file from model: " + filePath)// log.Println("File context:", fileContext)- // log.Println("currentState:", currentState)-sysPrompt := prompts.GetBuildFixesLineNumbersSysPrompt(activeBuild.FileDescription, activeBuild.FileContent, incorrectlyUpdated, reasoning)fileMessages := []openai.ChatCompletionMessage{diff --git a/app/server/model/plan/build_fix_stream.go b/app/server/model/plan/build_fix_stream.goindex f41a8e5a..1bf39c38 100644--- a/app/server/model/plan/build_fix_stream.go+++ b/app/server/model/plan/build_fix_stream.go@@ -73,7 +73,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -87,7 +88,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -111,7 +113,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -151,7 +154,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}}@@ -177,7 +181,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openplanBuildId: build.Id,convoMessageId: build.ConvoMessageId,filePath: filePath,- currentState: fileState.updated,+ preBuildState: fileState.updated,fileContent: activeBuild.FileContent,streamedChangesWithLineNums: streamed.Changes,overlapStrategy: overlapStrategy,@@ -195,7 +199,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -213,15 +218,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open}- // merge replacements- var replacements []*shared.Replacement- replacements = append(replacements, fileState.initialPlanFileResult.Replacements...)- replacements = append(replacements, planFileResult.Replacements...)-- planFileResult.Replacements = replacements-- // log.Println("listenStreamFixChanges - Plan file result:")- // spew.Dump(planFileResult)+ log.Println("listenStreamFixChanges - Plan file result:")+ spew.Dump(planFileResult)fileState.onFinishBuildFile(planFileResult)return@@ -237,7 +235,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("Build fix stream - Plan file result:")+ fileState.onFinishBuildFile(nil)return}}diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.goindex e045b9e6..578c9290 100644--- a/app/server/model/plan/build_result.go+++ b/app/server/model/plan/build_result.go@@ -24,7 +24,7 @@ type planResultParams struct {planBuildId stringconvoMessageId stringfilePath string- currentState string+ preBuildState stringfileContent stringoverlapStrategy OverlapStrategystreamedChangesWithLineNums []*shared.StreamedChangeWithLineNums@@ -35,20 +35,20 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, eplanId := params.planIdplanBuildId := params.planBuildIdfilePath := params.filePath- currentState := params.currentState+ preBuildState := params.preBuildStatestreamedChangesWithLineNums := params.streamedChangesWithLineNums// fileContent := params.fileContent- currentState = shared.AddLineNums(currentState)+ preBuildState = shared.AddLineNums(preBuildState)- currentStateLines := strings.Split(currentState, "\n")+ preBuildStateLines := strings.Split(preBuildState, "\n")// fileContentLines := strings.Split(fileContent, "\n")// log.Printf("\n\ngetPlanResult - path: %s\n", filePath)- // log.Println("getPlanResult - currentState:")- // log.Println(currentState)- // log.Println("getPlanResult - currentStateLines:")- // log.Println(currentStateLines)+ // log.Println("getPlanResult - preBuildState:")+ // log.Println(preBuildState)+ // log.Println("getPlanResult - preBuildStateLines:")+ // log.Println(preBuildStateLines)// log.Println("getPlanResult - fileContent:")// log.Println(fileContent)// log.Print("\n\n")@@ -76,18 +76,18 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, ereturn nil, "", false, fmt.Errorf("error getting lines from streamedChange: %v", err)}- if startLine > len(currentStateLines) {- log.Printf("Start line is greater than currentStateLines length: %d > %d\n", startLine, len(currentStateLines))- return nil, "", false, fmt.Errorf("start line is greater than currentStateLines length: %d > %d", startLine, len(currentStateLines))+ if startLine > len(preBuildStateLines) {+ log.Printf("Start line is greater than preBuildStateLines length: %d > %d\n", startLine, len(preBuildStateLines))+ return nil, "", false, fmt.Errorf("start line is greater than preBuildStateLines length: %d > %d", startLine, len(preBuildStateLines))}if endLine < 1 {log.Printf("End line is less than 1: %d\n", endLine)return nil, "", false, fmt.Errorf("end line is less than 1: %d", endLine)}- if endLine > len(currentStateLines) {- log.Printf("End line is greater than currentStateLines length: %d > %d\n", endLine, len(currentStateLines))- return nil, "", false, fmt.Errorf("end line is greater than currentStateLines length: %d > %d", endLine, len(currentStateLines))+ if endLine > len(preBuildStateLines) {+ log.Printf("End line is greater than preBuildStateLines length: %d > %d\n", endLine, len(preBuildStateLines))+ return nil, "", false, fmt.Errorf("end line is greater than preBuildStateLines length: %d > %d", endLine, len(preBuildStateLines))}if startLine < highestEndLine {@@ -115,9 +115,9 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, e}if startLine == endLine {- old = currentStateLines[startLine-1]+ old = preBuildStateLines[startLine-1]} else {- old = strings.Join(currentStateLines[startLine-1:endLine], "\n")+ old = strings.Join(preBuildStateLines[startLine-1:endLine], "\n")}// log.Printf("getPlanResult - old: %s\n", old)@@ -132,18 +132,18 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, string, bool, e}sort.Slice(replacements, func(i, j int) bool {- iIdx := strings.Index(currentState, replacements[i].Old)- jIdx := strings.Index(currentState, replacements[j].Old)+ iIdx := strings.Index(preBuildState, replacements[i].Old)+ jIdx := strings.Index(preBuildState, replacements[j].Old)return iIdx < jIdx})log.Println("Will apply replacements")- // log.Println("currentState:", currentState)+ // log.Println("preBuildState:", preBuildState)// log.Println("Replacements:")// spew.Dump(replacements)- updated, allSucceeded := shared.ApplyReplacements(currentState, replacements, true)+ updated, allSucceeded := shared.ApplyReplacements(preBuildState, replacements, true)updated = shared.RemoveLineNums(updated)diff --git a/app/server/model/plan/build_state.go b/app/server/model/plan/build_state.goindex ff40f62d..c938d8c9 100644--- a/app/server/model/plan/build_state.go+++ b/app/server/model/plan/build_state.go@@ -28,13 +28,12 @@ type activeBuildStreamFileState struct {build *db.PlanBuildcurrentPlanState *shared.CurrentPlanStateactiveBuild *types.ActiveBuild- currentState string+ preBuildState stringlineNumsNumRetry intverifyFileNumRetry intfixFileNumRetry int// fullChangesRetry intstreamedChangesWithLineNums []*shared.StreamedChangeWithLineNumsupdated string- initialPlanFileResult *db.PlanFileResultincorrectlyUpdatedReasoning string}diff --git a/app/server/model/plan/build_stream_line_nums.go b/app/server/model/plan/build_stream_line_nums.goindex 19b1c4b4..6fd2d356 100644--- a/app/server/model/plan/build_stream_line_nums.go+++ b/app/server/model/plan/build_stream_line_nums.go@@ -23,7 +23,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(strcurrentOrgId := fileState.currentOrgIdplanId := fileState.plan.Idbranch := fileState.branch- currentState := fileState.currentState+ preBuildState := fileState.preBuildStateactiveBuild := fileState.activeBuildactivePlan := GetActivePlan(planId, branch)@@ -136,14 +136,14 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(stroverlapStrategy = OverlapStrategySkip}- planFileResult, _, allSucceeded, err := getPlanResult(+ planFileResult, updatedFile, allSucceeded, err := getPlanResult(planResultParams{orgId: currentOrgId,planId: planId,planBuildId: build.Id,convoMessageId: build.ConvoMessageId,filePath: filePath,- currentState: currentState,+ preBuildState: preBuildState,fileContent: activeBuild.FileContent,streamedChangesWithLineNums: streamed.Changes,overlapStrategy: overlapStrategy,@@ -179,29 +179,14 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(strType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(planFileResult)-- // The verification loop below works, but is too heavy on tokens and also seems to hit OpenAI rate limits on complex tasks- // Going back to a simple build for now- // Semaphores may help to throttle calls, but had trouble getting them to work-- // hash := sha256.Sum256([]byte(updatedFile))- // sha := hex.EncodeToString(hash[:])- // log.Printf("listenStream - %s - updated content hash: %s\n", filePath, sha)+ fileState.updated = updatedFile- // fileState.updated = updatedFile- // fileState.initialPlanFileResult = planFileResult-- // select {- // case <-activePlan.Ctx.Done():- // log.Println("listenStream - Context canceled. Exiting.")- // return- // case <-time.After(time.Duration(rand.Intn(1001)) * time.Millisecond):- // break- // }- // fileState.verifyFileBuild()+ log.Println("build stream - Plan file result:")+ log.Printf("updatedFile exists: %v\n", updatedFile != "")+ log.Printf("toVerifyPlanFileResult exists: %v\n", planFileResult != nil)+ fileState.onFinishBuildFile(planFileResult)return} else if len(delta.ToolCalls) == 0 {log.Println("listenStream - Stream chunk missing function call.")diff --git a/app/server/model/plan/build_verify.go b/app/server/model/plan/build_verify.goindex fe81dd40..1b3436e4 100644--- a/app/server/model/plan/build_verify.go+++ b/app/server/model/plan/build_verify.go@@ -16,7 +16,8 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {branch := fileState.branchclients := fileState.clientsconfig := fileState.settings.ModelPack.Builder- currentState := fileState.currentState+ preBuildState := fileState.activeBuild.ToVerifyPreBuildState+ updated := fileState.activeBuild.ToVerifyUpdatedStateactivePlan := GetActivePlan(planId, branch)@@ -30,9 +31,14 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {log.Println("verifyFileBuild - Getting file from model: " + filePath)// log.Println("File context:", fileContext)- // log.Println("currentState:", currentState)+ 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(currentState, activeBuild.FileDescription, activeBuild.FileContent)+ sysPrompt := prompts.GetVerifyPrompt(preBuildState, updated, activeBuild.FileDescription, activeBuild.FileContent)++ log.Println("verify sysPrompt:\n", sysPrompt)fileMessages := []openai.ChatCompletionMessage{{diff --git a/app/server/model/plan/build_verify_stream.go b/app/server/model/plan/build_verify_stream.goindex 16c96d5e..ff60f075 100644--- a/app/server/model/plan/build_verify_stream.go+++ b/app/server/model/plan/build_verify_stream.go@@ -69,7 +69,10 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)++ log.Println("build verify - error - Plan file result:")++ fileState.onFinishBuildFile(nil)return}@@ -83,7 +86,8 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("build verify - no choices - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -108,7 +112,8 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("build verify - invalid json - Plan file result:")+ fileState.onFinishBuildFile(nil)return}@@ -145,7 +150,8 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("build verify - streamed.IsCorrect - Plan file result:")+ fileState.onFinishBuildFile(nil)} else {log.Printf("listenStreamVerifyOutput - File %s: Streamed verify result is incorrect: %s\n", filePath, streamed.Reasoning)@@ -174,7 +180,8 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opType: shared.StreamMessageBuildInfo,BuildInfo: buildInfo,})- fileState.onFinishBuildFile(fileState.initialPlanFileResult)+ log.Println("build verify - retry - Plan file result:")+ 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/prompts/build.go b/app/server/model/prompts/build.goindex 85206cf0..d1d151cb 100644--- a/app/server/model/prompts/build.go+++ b/app/server/model/prompts/build.go@@ -8,21 +8,21 @@ import ("github.com/sashabaranov/go-openai/jsonschema")-func GetBuildLineNumbersSysPrompt(filePath, currentState, desc, changes string) string {+func GetBuildLineNumbersSysPrompt(filePath, preBuildState, desc, changes string) string {// hash := sha256.Sum256([]byte(currentState))// sha := hex.EncodeToString(hash[:])// log.Println("GetBuildLineNumbersSysPrompt currentState sha:", sha)- currentStateWithLineNums := shared.AddLineNums(currentState)+ preBuildStateWithLineNums := shared.AddLineNums(preBuildState)- return getListChangesLineNumsPrompt() + "\n\n" + getBuildCurrentStatePrompt(filePath, currentStateWithLineNums) + "\n\n" + getBuildPromptWithLineNums(desc, changes)+ return getListChangesLineNumsPrompt() + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n" + getBuildPromptWithLineNums(desc, changes)}func GetBuildFixesLineNumbersSysPrompt(desc, changes, updated, reasoning string) string {// hash := sha256.Sum256([]byte(updated))// sha := hex.EncodeToString(hash[:])- // log.Println("GetBuildFixesLineNumbersSysPrompt currentState sha:", sha)+ // log.Println("GetBuildFixesLineNumbersSysPrompt updated sha:", sha)updatedWithLineNums := shared.AddLineNums(updated)@@ -59,12 +59,12 @@ func getBuildPromptForFixesWithLineNums(desc, changes, updated, reasoning stringreturn s}-func getBuildCurrentStatePrompt(filePath, currentState string) string {- if currentState == "" {+func getPreBuildStatePrompt(filePath, preBuildState string) string {+ if preBuildState == "" {return ""}- return fmt.Sprintf("**The current file is %s. Original state of the file:**\n```\n%s\n```", filePath, currentState) + "\n\n"+ return fmt.Sprintf("**The current file is %s. Original state of the file:**\n```\n%s\n```", filePath, preBuildState) + "\n\n"}const replacementIntro = `@@ -128,7 +128,9 @@ If the 'hasChange' property is false, the 'new' property must be an empty string`const lineNumsRulesPrompt = `-You ABSOLUTELY MUST NOT generate overlapping changes. Group smaller changes together into larger changes where necessary to avoid overlap. Only generate multiple changes when you are ABSOLUTELY CERTAIN that they do not overlap--otherwise group them together into a single change. If changes are close to each other (within several lines), group them together into a single change. Lean towards grouping changes together and making fewer, larger changes rather than many small changes, unless the changes are completely independent of each other and not close to each other in the file. It's ok to have just one change if that's all that's needed.+You ABSOLUTELY MUST NOT generate overlapping changes. Group smaller changes together into larger changes where necessary to avoid overlap. Only generate multiple changes when you are ABSOLUTELY CERTAIN that they do not overlap--otherwise group them together into a single change. If changes are close to each other (within several lines), group them together into a single change. You MUST group changes together and make fewer, larger changes rather than many small changes, unless the changes are completely independent of each other and not close to each other in the file. You MUST NEVER generate changes that are adjacent or close to adjacent. Adjacent or closely adjacent changes MUST ALWAYS be grouped into a single larger change.++Furthermore, unless doing so would require a very large change because some changes are far apart in the file, it's ideal to call the 'listChangesWithLineNums' with just a SINGLE change.Changes must be ordered in the array according to the order they appear in the file. The 'startLineString' of each 'old' property must come after the 'endLineString' of the previous 'old' property. Changes MUST NOT overlap. If a change is dependent on another change or intersects with it, group those changes together into a single change.`@@ -277,37 +279,63 @@ var ListReplacementsFn = openai.FunctionDefinition{},}-func GetVerifyPrompt(currentState, desc, changes string) string {- return `-Based on an original file, 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?+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?++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.'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.+`+ if preBuildState != "" {+ s += `---**Original file:**+## **Original file:**-` + currentState + `+` + preBuildState + `--+`+ }-**Description of the proposed updates from AI-generated plan:**+ s += `+## **Description of the proposed updates from AI-generated plan:**` + desc + `---**Proposed updates:**+## **Proposed updates:**` + changes + `--+`++ if preBuildState != "" {+ s += `++## **Updated file:**++`+ } else {+ s += `+ ## **New file:**++ `+ }++ s += updated + `Now call the 'verifyOutput' function with a valid JSON object that includes the 'reasoning', and 'isCorrect' keys. You must always call 'verifyOutput' with a valid JSON object. Don't call any other function.`++ return s}var VerifyOutputFn = openai.FunctionDefinition{diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.goindex 3e89c0f3..153ce8e0 100644--- a/app/server/types/active_plan.go+++ b/app/server/types/active_plan.go@@ -29,10 +29,13 @@ type ActiveBuild struct {VerifyBufferTokens int// FullChangeBuffer string// FullChangeBufferTokens int- FixBuffer string- FixBufferTokens int- Success bool- Error error+ FixBuffer string+ FixBufferTokens int+ Success bool+ Error error+ IsVerification bool+ ToVerifyPreBuildState string+ ToVerifyUpdatedState string}type subscription struct {