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
new build system working, tested, and very effective
Dane Schneidered96367b94ec
diff --git a/app/cli/changes_tui/main_viewport.go b/app/cli/changes_tui/main_viewport.goindex fd85bc63..9ee6d864 100644--- a/app/cli/changes_tui/main_viewport.go+++ b/app/cli/changes_tui/main_viewport.go@@ -101,7 +101,7 @@ func (m changesUIModel) renderMainViewHeader() string {header = fmt.Sprintf(" %s New file: %s", icon, m.selectionInfo.currentPath)} else {- header = " 👉 " + m.selectionInfo.currentRep.StreamedChange.Summary+ header = " 👉 " + m.selectionInfo.currentRep.GetSummary()}return style.Render(header)diff --git a/app/server/go.mod b/app/server/go.modindex e164e314..650c752e 100644--- a/app/server/go.mod+++ b/app/server/go.mod@@ -24,13 +24,14 @@ require (github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirectgithub.com/olekukonko/tablewriter v0.0.5 // indirectgithub.com/pkoukk/tiktoken-go v0.1.7 // indirect+ github.com/pmezard/go-difflib v1.0.0 // indirectgithub.com/rivo/uniseg v0.4.7 // indirectgithub.com/shopspring/decimal v1.4.0 // indirectgithub.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirectgo.uber.org/atomic v1.11.0 // indirectgolang.org/x/image v0.19.0 // indirect- golang.org/x/mod v0.11.0 // indirectgolang.org/x/sys v0.24.0 // indirect+ gopkg.in/yaml.v3 v3.0.1 // indirect)require (@@ -43,7 +44,7 @@ require (github.com/lib/pq v1.10.9github.com/rs/cors v1.11.0github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6- golang.org/x/tools v0.10.0+ github.com/stretchr/testify v1.8.3)replace github.com/plandex/plandex/shared => ../shareddiff --git a/app/server/go.sum b/app/server/go.sumindex 2fe140d6..39ff84e6 100644--- a/app/server/go.sum+++ b/app/server/go.sum@@ -115,6 +115,7 @@ golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.goindex 68ba0e05..1544c637 100644--- a/app/server/model/plan/build_exec.go+++ b/app/server/model/plan/build_exec.go@@ -282,7 +282,17 @@ func (fileState *activeBuildStreamFileState) buildFile() {activeBuild.CurrentFileTokens = currentNumTokens}- fileState.buildExpandReferences()+ if fileState.parser != nil && !fileState.preBuildStateSyntaxInvalid {+ log.Println("buildFile - building structured edits")++ fileState.buildStructuredEdits()+ } else {+ log.Println("buildFile - building expand references")+ log.Printf("fileState.parser == nil: %v\n", fileState.parser == nil)+ log.Printf("fileState.preBuildStateSyntaxInvalid: %v\n", fileState.preBuildStateSyntaxInvalid)++ fileState.buildExpandReferences()+ }}func (fileState *activeBuildStreamFileState) buildFileLineNums() {@@ -304,7 +314,6 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {log.Println("buildFileLineNums - getting file from model: " + filePath)// log.Println("File context:", fileContext)-// log.Println("currentState:", currentState)sysPrompt := prompts.GetBuildLineNumbersSysPrompt(filePath, originalFile, fmt.Sprintf("%s\n\n```%s```", activeBuild.FileDescription, activeBuild.FileContent))diff --git a/app/server/model/plan/build_fix_result.go b/app/server/model/plan/build_fix_result.goindex 488d0b30..d39f8ffb 100644--- a/app/server/model/plan/build_fix_result.go+++ b/app/server/model/plan/build_fix_result.go@@ -142,7 +142,7 @@ func (fileState *activeBuildStreamFileState) onFixResult(res types.ChangesWithLi}func (fileState *activeBuildStreamFileState) fixRetryOrAbort(err error) {- if fileState.fixFileNumRetry < MaxBuildStreamErrorRetries {+ if fileState.fixFileNumRetry < MaxBuildErrorRetries {fileState.fixFileNumRetry++fileState.activeBuild.FixBuffer = ""fileState.activeBuild.FixBufferTokens = 0diff --git a/app/server/model/plan/build_fix_stream.go b/app/server/model/plan/build_fix_stream.goindex ef79575a..65685932 100644--- a/app/server/model/plan/build_fix_stream.go+++ b/app/server/model/plan/build_fix_stream.go@@ -155,7 +155,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open// if stream finished and it's not a usage chunk, keep listening for usage chunkif streamFinished {- log.Printf("listenStreamFixChanges - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ // log.Printf("listenStreamFixChanges - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)continue}diff --git a/app/server/model/plan/build_load.go b/app/server/model/plan/build_load.goindex 1dd4e1c8..75ca8ab3 100644--- a/app/server/model/plan/build_load.go+++ b/app/server/model/plan/build_load.go@@ -4,7 +4,9 @@ import ("fmt""log""net/http"+ "path/filepath""plandex-server/db"+ "plandex-server/syntax""plandex-server/types""github.com/plandex/plandex/shared"@@ -134,6 +136,28 @@ func (state *activeBuildStreamFileState) loadBuildFile(activeBuild *types.ActiveconvoMessageId := activeBuild.ReplyId+ ext := filepath.Ext(filePath)+ parser, lang, backupParser, backupLang := syntax.GetParserForExt(ext)++ if parser != nil {+ state.parser = parser+ state.language = lang+ } else if backupParser != nil {+ state.parser = backupParser+ state.language = backupLang+ }++ if state.parser != nil {+ validationRes, err := syntax.Validate(activePlan.Ctx, filePath, state.preBuildState)+ if err != nil {+ log.Printf(" error validating original file syntax: %v\n", err)+ return fmt.Errorf("error validating original file syntax: %v", err)+ }+ if validationRes.HasParser && !validationRes.TimedOut && !validationRes.Valid {+ state.preBuildStateSyntaxInvalid = true+ }+ }+build := &db.PlanBuild{OrgId: currentOrgId,PlanId: planId,diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.goindex 9ce46b75..26cfba09 100644--- a/app/server/model/plan/build_result.go+++ b/app/server/model/plan/build_result.go@@ -451,7 +451,7 @@ func (fileState *activeBuildStreamFileState) onLineNumsBuildResult(res types.Cha}func (fileState *activeBuildStreamFileState) lineNumsRetryOrError(err error) {- if fileState.lineNumsNumRetry < MaxBuildStreamErrorRetries {+ if fileState.lineNumsNumRetry < MaxBuildErrorRetries {fileState.lineNumsNumRetry++fileState.activeBuild.WithLineNumsBuffer = ""fileState.activeBuild.WithLineNumsBufferTokens = 0diff --git a/app/server/model/plan/build_state.go b/app/server/model/plan/build_state.goindex 249fce0d..e675b173 100644--- a/app/server/model/plan/build_state.go+++ b/app/server/model/plan/build_state.go@@ -6,9 +6,10 @@ import ("github.com/plandex/plandex/shared""github.com/sashabaranov/go-openai"+ sitter "github.com/smacker/go-tree-sitter")-const MaxBuildStreamErrorRetries = 3 // uses semi-exponential backoff so be careful with this+const MaxBuildErrorRetries = 3 // uses semi-exponential backoff so be careful with thisconst FixSyntaxRetries = 2const FixSyntaxEpochs = 2@@ -27,17 +28,21 @@ type activeBuildStreamState struct {type activeBuildStreamFileState struct {*activeBuildStreamState- filePath string- convoMessageId string- build *db.PlanBuild- currentPlanState *shared.CurrentPlanState- activeBuild *types.ActiveBuild- preBuildState string-- expandRefsNumRetry int- lineNumsNumRetry int- verifyFileNumRetry int- fixFileNumRetry int+ filePath string+ convoMessageId string+ build *db.PlanBuild+ currentPlanState *shared.CurrentPlanState+ activeBuild *types.ActiveBuild+ preBuildState string+ parser *sitter.Parser+ language string+ preBuildStateSyntaxInvalid bool++ structuredEditNumRetry int+ expandRefsNumRetry int+ lineNumsNumRetry int+ verifyFileNumRetry int+ fixFileNumRetry intsyntaxNumRetry intsyntaxNumEpoch intdiff --git a/app/server/model/plan/build_stream_line_nums.go b/app/server/model/plan/build_stream_line_nums.goindex 65ff8939..567c74a1 100644--- a/app/server/model/plan/build_stream_line_nums.go+++ b/app/server/model/plan/build_stream_line_nums.go@@ -159,7 +159,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str// if stream finished and it's not a usage chunk, keep listening for usage chunkif streamFinished {- log.Printf("listenStream - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ // log.Printf("listenStream - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)continue}diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.gonew file mode 100644index 00000000..7f61a1ae--- /dev/null+++ b/app/server/model/plan/build_structured_edits.go@@ -0,0 +1,279 @@+package plan++import (+ "encoding/xml"+ "fmt"+ "log"+ "math/rand"+ "plandex-server/db"+ "plandex-server/hooks"+ "plandex-server/model"+ "plandex-server/model/prompts"+ "plandex-server/syntax"+ "plandex-server/types"+ "strings"+ "time"++ "github.com/davecgh/go-spew/spew"+ "github.com/plandex/plandex/shared"+ "github.com/sashabaranov/go-openai"+)++func (fileState *activeBuildStreamFileState) buildStructuredEdits() {+ auth := fileState.auth+ filePath := fileState.filePath+ activeBuild := fileState.activeBuild+ clients := fileState.clients+ planId := fileState.plan.Id+ branch := fileState.branch+ config := fileState.settings.ModelPack.Builder+ originalFile := fileState.preBuildState+ parser := fileState.parser++ if parser == nil {+ log.Println("buildStructuredEdits - tree-sitter parser is nil")+ fileState.onBuildFileError(fmt.Errorf("tree-sitter parser is nil"))+ return+ }++ activePlan := GetActivePlan(planId, branch)++ if activePlan == nil {+ log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)+ fileState.onBuildFileError(fmt.Errorf("active plan not found for plan ID %s and branch %s\n", planId, branch))+ return+ }++ log.Println("buildStructuredEdits - getting references prompt")++ anchorsSysPrompt := prompts.GetSemanticAnchorsPrompt(filePath, originalFile, activeBuild.FileContent, activeBuild.FileDescription)++ anchorsFileMessages := []openai.ChatCompletionMessage{+ {+ Role: openai.ChatMessageRoleSystem,+ Content: anchorsSysPrompt,+ },+ }++ promptTokens, err := shared.GetNumTokens(anchorsSysPrompt)++ if err != nil {+ log.Printf("buildStructuredEdits - error getting num tokens for prompt: %v\n", err)+ fileState.onBuildFileError(fmt.Errorf("error getting num tokens for prompt: %v", err))+ return+ }++ inputTokens := prompts.ExtraTokensPerRequest + prompts.ExtraTokensPerMessage + promptTokens++ fileState.inputTokens = inputTokens++ _, apiErr := hooks.ExecHook(hooks.WillSendModelRequest, hooks.HookParams{+ Auth: auth,+ Plan: fileState.plan,+ WillSendModelRequestParams: &hooks.WillSendModelRequestParams{+ InputTokens: inputTokens,+ OutputTokens: shared.AvailableModelsByName[fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName].DefaultReservedOutputTokens,+ ModelName: fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName,+ },+ })+ if apiErr != nil {+ activePlan.StreamDoneCh <- apiErr+ return+ }++ log.Println("buildStructuredEdits - calling model for references")++ modelReq := openai.ChatCompletionRequest{+ Model: config.BaseModelConfig.ModelName,+ Messages: anchorsFileMessages,+ Temperature: config.Temperature,+ TopP: config.TopP,+ }++ envVar := config.BaseModelConfig.ApiKeyEnvVar+ client := clients[envVar]++ resp, err := model.CreateChatCompletionWithRetries(client, activePlan.Ctx, modelReq)++ if err != nil {+ log.Printf("buildStructuredEdits - error calling model: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error calling model: %v", err))+ return+ }++ log.Println("buildStructuredEdits - usage:")+ spew.Dump(resp.Usage)++ _, apiErr = hooks.ExecHook(hooks.DidSendModelRequest, hooks.HookParams{+ Auth: auth,+ Plan: fileState.plan,+ DidSendModelRequestParams: &hooks.DidSendModelRequestParams{+ InputTokens: resp.Usage.PromptTokens,+ OutputTokens: resp.Usage.CompletionTokens,+ ModelName: fileState.settings.ModelPack.Builder.BaseModelConfig.ModelName,+ ModelProvider: fileState.settings.ModelPack.Builder.BaseModelConfig.Provider,+ ModelPackName: fileState.settings.ModelPack.Name,+ ModelRole: shared.ModelRoleBuilder,+ Purpose: "Generated file update (structured edits)",+ },+ })++ if apiErr != nil {+ activePlan.StreamDoneCh <- apiErr+ return+ }++ if len(resp.Choices) == 0 {+ log.Printf("buildStructuredEdits - no choices in response\n")+ fileState.structuredEditRetryOrError(fmt.Errorf("no choices in response"))+ return+ }++ refsChoice := resp.Choices[0]+ content := refsChoice.Message.Content++ log.Println("buildStructuredEdits - content:")+ log.Println(content)++ anchorsXmlString, err := GetXMLTag(content, "SemanticAnchors")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing SemanticAnchors xml: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error parsing SemanticAnchors xml xml: %v", err))+ return+ }++ var anchorsElement types.SemanticAnchors++ err = xml.Unmarshal([]byte(anchorsXmlString), &anchorsElement)+ if err != nil {+ log.Printf("buildStructuredEdits - error unmarshalling xml: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error unmarshalling xml: %v", err))+ return+ }++ log.Printf("buildStructuredEdits - got %d anchors\n", len(anchorsElement.Anchors))++ anchorLines := make(map[int]int)++ for _, anchor := range anchorsElement.Anchors {+ fmt.Printf("anchor: %v\n", anchor)++ var originalLine, proposedLine int+ originalLine, err = shared.ExtractLineNumberWithPrefix(anchor.OriginalLine, "pdx-")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing anchor original line num: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error parsing anchor original line num: %v", err))+ return+ }++ proposedLine, err = shared.ExtractLineNumberWithPrefix(anchor.ProposedLine, "pdx-new-")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing anchor proposed line num: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error parsing anchor proposed line num: %v", err))+ return+ }++ anchorLines[proposedLine] = originalLine+ }++ fileContentLines := strings.Split(activeBuild.FileContent, "\n")++ var references []syntax.Reference+ var removals []syntax.Removal++ for i, line := range fileContentLines {+ line = strings.ToLower(strings.TrimSpace(line))+ if strings.Contains(line, "... existing code ...") {+ references = append(references, syntax.Reference(i+1))+ }+ if strings.Contains(line, "plandex: removed code") {+ removals = append(removals, syntax.Removal(i+1))+ }+ }++ updatedFile, err := syntax.ApplyChanges(activePlan.Ctx, fileState.language, parser, originalFile, activeBuild.FileContent, references, removals, anchorLines)+ if err != nil {+ log.Printf("buildStructuredEdits - error applying references: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error applying references: %v", err))+ return+ }++ buildInfo := &shared.BuildInfo{+ Path: filePath,+ NumTokens: 0,+ Finished: true,+ }+ activePlan.Stream(shared.StreamMessage{+ Type: shared.StreamMessageBuildInfo,+ BuildInfo: buildInfo,+ })+ time.Sleep(50 * time.Millisecond)++ fileState.updated = updatedFile++ replacements, err := db.GetDiffReplacements(originalFile, updatedFile)+ if err != nil {+ log.Printf("buildStructuredEdits - error getting diff replacements: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error getting diff replacements: %v", err))+ return+ }++ res := db.PlanFileResult{+ TypeVersion: 1,+ OrgId: fileState.plan.OrgId,+ PlanId: fileState.plan.Id,+ PlanBuildId: fileState.build.Id,+ ConvoMessageId: fileState.convoMessageId,+ Content: "",+ Path: filePath,+ Replacements: replacements,+ CanVerify: false, // no verification step with structural edits+ }++ if !fileState.preBuildStateSyntaxInvalid {+ validationRes, err := syntax.Validate(activePlan.Ctx, filePath, updatedFile)+ if err != nil {+ log.Printf("buildStructuredEdits - error validating syntax: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error validating syntax: %v", err))+ return+ }++ if validationRes.HasParser && !validationRes.TimedOut && !validationRes.Valid {+ log.Printf("buildStructuredEdits - syntax is invalid\n")+ }++ res.SyntaxValid = validationRes.Valid+ res.SyntaxErrors = validationRes.Errors+ }++ fileState.onFinishBuildFile(&res, updatedFile)+}++func (fileState *activeBuildStreamFileState) structuredEditRetryOrError(err error) {+ if fileState.structuredEditNumRetry < MaxBuildErrorRetries {+ fileState.structuredEditNumRetry++++ log.Printf("buildStructuredEdits - retrying expand refs file '%s' due to error: %v\n", fileState.filePath, err)++ activePlan := GetActivePlan(fileState.plan.Id, fileState.branch)++ if activePlan == nil {+ log.Printf("buildStructuredEdits - active plan not found for plan ID %s and branch %s\n", fileState.plan.Id, fileState.branch)+ fileState.onBuildFileError(fmt.Errorf("active plan not found for plan ID %s and branch %s", fileState.plan.Id, fileState.branch))+ return+ }++ select {+ case <-activePlan.Ctx.Done():+ log.Printf("buildStructuredEdits - context canceled\n")+ return+ case <-time.After(time.Duration(fileState.structuredEditNumRetry*fileState.structuredEditNumRetry)*200*time.Millisecond + time.Duration(rand.Intn(500))*time.Millisecond):+ break+ }++ fileState.buildStructuredEdits()+ } else {+ fileState.onBuildFileError(err)+ }++}diff --git a/app/server/model/plan/build_verify_result.go b/app/server/model/plan/build_verify_result.goindex 31e5241d..9ee5e56b 100644--- a/app/server/model/plan/build_verify_result.go+++ b/app/server/model/plan/build_verify_result.go@@ -60,7 +60,7 @@ func (fileState *activeBuildStreamFileState) onVerifyResult(res types.VerifyResu}func (fileState *activeBuildStreamFileState) verifyRetryOrAbort(err error) {- if fileState.verifyFileNumRetry < MaxBuildStreamErrorRetries {+ if fileState.verifyFileNumRetry < MaxBuildErrorRetries {fileState.verifyFileNumRetry++fileState.activeBuild.VerifyBuffer = ""fileState.activeBuild.VerifyBufferTokens = 0diff --git a/app/server/model/plan/build_verify_stream.go b/app/server/model/plan/build_verify_stream.goindex d0635af8..d6aa5de2 100644--- a/app/server/model/plan/build_verify_stream.go+++ b/app/server/model/plan/build_verify_stream.go@@ -156,7 +156,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op// if stream finished and it's not a usage chunk, keep listening for usage chunkif streamFinished {- log.Printf("listenStreamVerifyOutput - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ // log.Printf("listenStreamVerifyOutput - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)continue}diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 3cae5343..bfdf9562 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -172,8 +172,8 @@ mainLoop:// if stream finished and it's not a usage chunk, keeep listening for usage chunkif streamFinished {- log.Println("Tell stream finished—no usage chunk-will keep listening")- continue+ // log.Println("Tell stream finished—no usage chunk-will keep listening")+ // continue}if len(response.Choices) > 1 {diff --git a/app/server/model/prompts/build_update.go b/app/server/model/prompts/build_update.goindex 1dc26b1e..25e76751 100644--- a/app/server/model/prompts/build_update.go+++ b/app/server/model/prompts/build_update.go@@ -14,6 +14,8 @@ func GetSemanticAnchorsPrompt(filePath, preBuildState, changesFile, changesDescs += fmt.Sprintf("Proposed updates:\n%s\n```\n%s\n```", changesDesc, changesWithLineNums)+ fmt.Printf("SemanticAnchorsPrompt: %s\n", s)+return s}@@ -90,11 +92,11 @@ Then both the lines 'pdx-new-2: // Get response and parse JSON body' and 'pdxTo mark a line a semantic anchor, it must be very clear from the description of the change and the *proposed updates* that a line from the *proposed updates* is intended to match a line in the *original file*. Do NOT mark lines as semantic anchors simply because they are similar to a line in the *original file*. The line must be clearly intended to match a line in the *original file*. If it's ambiguous whether a line is intended to match a line in the *original file*, it is *not* a semantic anchor.-If a line in the *proposed updates* is identical to a line in the *original file*, but has changed position or is being used in a different context, it is *still not* a semantic anchor. You *must not* under any circumstances mark any line that is identical to a line in the *original file* as a semantic anchor.+If a line in the *proposed updates* is identical to a line in the *original file*, but has changed position or is being used in a different context, it is *still NOT* a semantic anchor. You *MUST NOT* under any circumstances mark any line that is identical to a line in the *original file* as a semantic anchor. Semantic anchors are only for lines that have *changed* in the *proposed updates* but are still clearly intended to match a line from the *original file*.If a line in the *proposed updates* is a semantic anchor and there is a comment (or multiple comments) associated with the line that is being modified, carefully consider if the comment should also be marked as a semantic anchor. If the comment or comments clearly map to a corresponding comment in the *original file*, and the comment is modified in the *proposed updates*, then it MUST be marked as a semantic anchor. Correctly marking comments as sematic anchors is just as important as marking other lines of code as semantic anchors.-First, do a succinct paragraph of general reasoning about the *proposed updates* and how they refer to the *original file*, focusing on the structure of each, which elements are changing, and how the changes map to the *original file*. Also make a brief note of any comments that are being modified or introduced in the *proposed updates* and whether/how they map to comments in the *original file*.+First, output a single *brief* paragraph of general reasoning about the *proposed updates* and how they refer to the *original file*, focusing on the structure of each, which elements are changing, and how the changes map to the *original file*. Also make a brief note of any comments that are being modified or introduced in the *proposed updates* and whether/how they map to comments in the *original file*. Do NOT output a list of semantic anchors in this paragraph—save that for the next section.Next, output xml with this structure:@@ -108,7 +110,7 @@ Next, output xml with this structure:Explanation of 'Anchor' tag attributes:- **reasoning**: A brief explanation of why this line in the *proposed updates* is intended to match a line in the *original file*.+ **reasoning**: A brief explanation of why this line in the *proposed updates* is a *semantic anchor*—why it's intended to match a line in the *original file* (even though it's *not* exactly equal to that line).**proposedLine**: The line number, prefixed by 'pdx-new-', in the *proposed updates* that is intended to match a line in the *original file*. MUST be a line that exists in the *proposed updates*.diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.goindex 7aa1b4ea..e21f1148 100644--- a/app/server/model/prompts/create.go+++ b/app/server/model/prompts/create.go@@ -11,218 +11,218 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context"[YOUR INSTRUCTIONS:]" +`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 does have a task*, create a plan for the task based on user-provided context using the following steps:-- 1. Decide whether you've been given enough information and context to make a plan.- - Do your best with whatever information and context you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information or context.- a. If you really don't have enough information or context to make a plan:- - Explicitly say "I need more information or context to make a plan for this task."- - Ask the user for more information or context and stop there.-- 2. Decide whether this task is small enough to be completed in a single response.- a. If so, describe the task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:- - src/main.rs:- - lib/term.go:- - 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" + `++ *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 does have a task*, create a plan for the task based on user-provided context using the following steps:++ 1. Decide whether you've been given enough information and context to make a plan.+ - Do your best with whatever information and context you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information or context.+ a. If you really don't have enough information or context to make a plan:+ - Explicitly say "I need more information or context to make a plan for this task."+ - Ask the user for more information or context and stop there.++ 2. Decide whether this task is small enough to be completed in a single response.+ a. If so, describe the task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:+ - src/main.rs:+ - lib/term.go:+ - 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. Subtasks MUST ALWAYS be numbered. Stop there.- - If you are already working on a subtask and the subtask is still too large to be implemented in a single response, it should be further broken down into smaller subtasks. In that case, explicitly say "Let's further break up this subtask", further divide the subtask into even smaller steps, and list them in a numbered list. Stop there. Do NOT do this repetitively for the same subtask. Only break down a given subtask into smaller steps once.- - Be thorough and exhaustive in your list of subtasks. Ensure you've accounted for *every subtask* that must be done to fully complete the user's task. Ensure that you list *every* file that needs to be created or updated. Be specific and detailed in your list of subtasks.- - Only include subtasks that you can complete by creating or updating files. If a subtask requires executing code or commands, mention it to the user, but do not include it as a subtask in the plan. Do not include subtasks like "Testing and integration" or "Deployment" that require executing code or commands. Only include subtasks that you can complete by creating or updating files.- - Only break the task up into subtasks that you can do yourself. If a subtask requires executing code or commands, or other tasks that go beyond coding like testing or verifying, deploying, user testing, and son, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that can be completed directly with code by creating or updating files.- - Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.- - Do NOT ask the user to confirm after you've made subtasks. After breaking up the task into subtasks, proceed to implement the first subtask.-- ## Code blocks and files+ #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. Subtasks MUST ALWAYS be numbered. Stop there.+ - If you are already working on a subtask and the subtask is still too large to be implemented in a single response, it should be further broken down into smaller subtasks. In that case, explicitly say "Let's further break up this subtask", further divide the subtask into even smaller steps, and list them in a numbered list. Stop there. Do NOT do this repetitively for the same subtask. Only break down a given subtask into smaller steps once.+ - Be thorough and exhaustive in your list of subtasks. Ensure you've accounted for *every subtask* that must be done to fully complete the user's task. Ensure that you list *every* file that needs to be created or updated. Be specific and detailed in your list of subtasks.+ - Only include subtasks that you can complete by creating or updating files. If a subtask requires executing code or commands, mention it to the user, but do not include it as a subtask in the plan. Do not include subtasks like "Testing and integration" or "Deployment" that require executing code or commands. Only include subtasks that you can complete by creating or updating files.+ - Only break the task up into subtasks that you can do yourself. If a subtask requires executing code or commands, or other tasks that go beyond coding like testing or verifying, deploying, user testing, and son, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that can be completed directly with code by creating or updating files.+ - Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.+ - Do NOT ask the user to confirm after you've made subtasks. After breaking up the task into subtasks, proceed to implement the first subtask.++ ## Code blocks and files- Always precede code blocks in a plan with the file path as described above in 2a. Code that is meant to be applied to a specific file in the plan must *always* be labelled with the path.-- If code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.-- 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 as a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. You must *never* create files with absolute paths like '/etc/config.txt'. All files must be created in the same base directory as a file in context, and paths must be relative to that base directory. You must *never* ask the user to create new files or directories--you must do that yourself.+ Always precede code blocks in a plan with the file path as described above in 2a. Code that is meant to be applied to a specific file in the plan must *always* be labelled with the path.++ If code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.++ 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 as a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. You must *never* create files with absolute paths like '/etc/config.txt'. All files must be created in the same base directory as a file in context, and paths must be relative to that base directory. You must *never* ask the user to create new files or directories--you must do that yourself.- **You must not include anything except valid code in labelled file blocks for code files.** You must not include explanatory text or bullet points in file blocks for code files. Only code. Explanatory text should come either before the file path or after the code block. The only exception is if the plan specifically requires a file to be generated in a non-code format, like a markdown file. In that case, you can include the non-code content in the file block. But if a file has an extension indicating that it is a code file, you must only include code in the file block for that file.+ **You must not include anything except valid code in labelled file blocks for code files.** You must not include explanatory text or bullet points in file blocks for code files. Only code. Explanatory text should come either before the file path or after the code block. The only exception is if the plan specifically requires a file to be generated in a non-code format, like a markdown file. In that case, you can include the non-code content in the file block. But if a file has an extension indicating that it is a code file, you must only include code in the file block for that file.- Files MUST NOT be labelled with a comment like "// File to create: src/main.rs" or "// File to update: src/main.rs".+ Files MUST NOT be labelled with a comment like "// File to create: src/main.rs" or "// File to update: src/main.rs".- File block labels MUST ONLY include a *single* file path. You must NEVER include multiple files in a single file block. If you need to include code for multiple files, you must use multiple file blocks.+ File block labels MUST ONLY include a *single* file path. You must NEVER include multiple files in a single file block. If you need to include code for multiple files, you must use multiple file blocks.- You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening triple backticks of the code block. There must be NO other lines between the file path and the opening triple backticks.+ You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening triple backticks of the code block. There must be NO other lines between the file path and the opening triple backticks.- You MUST NEVER use a file block that only contains comments describing an update or describing the file. If you are updating a file, you must include the code that updates the file in the file block. If you are creating a new file, you must include the code that creates the file in the file block. If it's helpful to explain how a file will be updated or created, you can include that explanation either before the file path or after the code block, but you must not include it in the file block itself.+ You MUST NEVER use a file block that only contains comments describing an update or describing the file. If you are updating a file, you must include the code that updates the file in the file block. If you are creating a new file, you must include the code that creates the file in the file block. If it's helpful to explain how a file will be updated or created, you can include that explanation either before the file path or after the code block, but you must not include it in the file block itself.- You MUST NOT use the labelled file block format followed by triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.+ You MUST NOT use the labelled file block format followed by triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.- If code is being removed from a file, the removal must be shown in a labelled file block according to your instructions. Use a comment within the file block to denote the removal like '// Remove the fooBar function' or '// Remove the loop'. Do NOT use any other formatting apart from a labelled file block to denote the removal. Ensure the comment denoting the removal is clear and unambiguously describes the code that is being removed.+ If a change is related to code in an existing file in context, make the change as an update to the existing file. Do NOT create a new file for a change that applies to an existing file in context. For example, if there is an 'Page.tsx' file in the existing context and the user has asked you to update the structure of the page component, make the change in the existing 'Page.tsx' file. Do NOT create a new file like 'page.tsx' or 'NewPage.tsx' for the change. If the user has specifically asked you to apply a change to a new file, then you can create a new file. If there is no existing file that makes sense to apply a change to, then you can create a new file.- If a change is related to code in an existing file in context, make the change as an update to the existing file. Do NOT create a new file for a change that applies to an existing file in context. For example, if there is an 'Page.tsx' file in the existing context and the user has asked you to update the structure of the page component, make the change in the existing 'Page.tsx' file. Do NOT create a new file like 'page.tsx' or 'NewPage.tsx' for the change. If the user has specifically asked you to apply a change to a new file, then you can create a new file. If there is no existing file that makes sense to apply a change to, then you can create a new file.+ For code in markdown blocks, always include the language name after the opening triple backticks.- For code in markdown blocks, always include the language name after the opening triple backticks.+ If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.++ Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.- If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.-- Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.+ An exception to the above instructions on comments are if a file block is empty because you removed everything in it. In that case, leave a brief one-line comment starting with 'Removed' that describes unambiguously what was removed so that the file block isn't empty.- An exception to the above instructions on comments are if a file block is empty because you removed everything in it. In that case, leave a brief one-line comment starting with 'Removed' that describes unambiguously what was removed so that the file block isn't empty.+ When you are updating an existing file in context: include the *minimum amount of code* necessary in code blocks to describe the suggested changes. Include only lines that are changing and lines that make it clear where the change should be applied. When updating an existing file in context, you can use the *reference comment* "// ... existing code ..." (with the appropriate comment symbol for the programming language) instead of including large sections from the original file in order to make it clear where changes should be applied. You *must not* include more lines from the original file than are absolutely necessary to make the location, structure, and order of suggested changes clear.++ Instead, show only the code that is changing and the immediately surrounding code that is necessary to understand the changes. Use the comment "// ... existing code ..." (with the appropriate comment symbol for the programming language) to replace sections of code from the original file and denote where the existing code should be placed. Again, this only applies when you are updating an existing file in context. It does not apply when you are creating a new file. You MUST NOT use the comment "// ... existing code ..." (or any equivalent) when creating a new file.- When you are updating an existing file in context: include the *minimum amount of code* necessary in code blocks to describe the suggested changes. Include only lines that are changing and lines that make it clear where the change should be applied. When updating an existing file in context, you can use the comment "// ... existing code ..." (adapted for the programming language) instead of including large sections from the original file in order to make it clear where changes should be applied. You *must not* include large sections of the original file unless it is absolutely necessary to make the suggested changes clear. Instead show only the code that is changing and the immediately surrounding code that is necessary to understand the changes. Use the comment "// ... existing code ..." (adapted for the programming language) to replace sections of code from the original file and denote where the existing code should be placed. Again, this only applies when you are updating an existing file in context. It does not apply when you are creating a new file. You MUST NOT use the comment "// ... existing code ..." (or any equivalent) when creating a new file.+ ` + UpdateFormatPrompt + `- ` + UpdateFormatPrompt + `+ As much as possible, do not include placeholders in code blocks like "// implement functionality here". Unless you absolutely cannot implement the full code block, do not include a placeholder denoted with comments. Do your best to implement the functionality rather than inserting a placeholder. You **MUST NOT** include placeholders just to shorten the code block. If the task is too large to implement in a single code block, you should break the task down into smaller steps and **FULLY** implement each step.- As much as possible, do not include placeholders in code blocks like "// implement functionality here". Unless you absolutely cannot implement the full code block, do not include a placeholder denoted with comments. Do your best to implement the functionality rather than inserting a placeholder. You **MUST NOT** include placeholders just to shorten the code block. If the task is too large to implement in a single code block, you should break the task down into smaller steps and **FULLY** implement each step.+ If you are outputting some code for illustrative or explanatory purpose and not because you are updating that code, you MUST NOT use a labelled file block. Instead output the label with NO PRECEDING DASH and NO COLON postfix. Use a conversational sentence like 'This code in src/main.rs.' to label the code. This is the only exception to the rule that all code blocks must be labelled with a file path. Labelled code blocks are ONLY for code that is being created or modified in the plan.- If you are outputting some code for illustrative or explanatory purpose and not because you are updating that code, you MUST NOT use a labelled file block. Instead output the label with NO PRECEDING DASH and NO COLON postfix. Use a conversational sentence like 'This code in src/main.rs.' to label the code. This is the only exception to the rule that all code blocks must be labelled with a file path. Labelled code blocks are ONLY for code that is being created or modified in the plan.+ As much as possible, the code you suggest should be robust, complete, and ready for production.- As much as possible, the code you suggest should be robust, complete, and ready for production.+ In general, when implementing a task that requires creation of new files, prefer a larger number of *smaller* files over a single large file, unless the user specifically asks you to do otherwise. Smaller files are easier and faster to work with. Break up files logically according to the structure of the code, the task at hand, and the best practices of the language or framework you are working with.- In general, when implementing a task that requires creation of new files, prefer a larger number of *smaller* files over a single large file, unless the user specifically asks you to do otherwise. Smaller files are easier and faster to work with. Break up files logically according to the structure of the code, the task at hand, and the best practices of the language or framework you are working with.+ ## Do the task yourself and don't give up- ## Do the task yourself and don't give up+ **Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.- **Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.+ **You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.- **You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.+ **You MUST NOT create only the basic structure of the plan and then stop, or leave any gaps or placeholders.** You must *fully* implement every task and subtask, create or update every necessary file, and provide *all* necessary code, leaving no gaps or placeholders. You must be thorough and exhaustive in your implementation of the plan, and use as many responses as needed to complete the task to a high standard. In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated. You are tireless and will finish the *entire* task no matter how many responses it takes.- **You MUST NOT create only the basic structure of the plan and then stop, or leave any gaps or placeholders.** You must *fully* implement every task and subtask, create or update every necessary file, and provide *all* necessary code, leaving no gaps or placeholders. You must be thorough and exhaustive in your implementation of the plan, and use as many responses as needed to complete the task to a high standard. In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated. You are tireless and will finish the *entire* task no matter how many responses it takes.+ ## Focus on what the user has asked for and don't add extra code or features- ## Focus on what the user has asked for and don't add extra code or features+ Don't include extra code, features, or tasks beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it. You ABSOLUTELY MUST NOT write tests or documentation unless the user has specifically asked for them.- Don't include extra code, features, or tasks beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it. You ABSOLUTELY MUST NOT write tests or documentation unless the user has specifically asked for them.+ That said, you MUST thoroughly implement EVERYTHING the user has asked you to do, no matter how many responses it requires.- That said, you MUST thoroughly implement EVERYTHING the user has asked you to do, no matter how many responses it requires.+ ## Working on subtasks- ## Working on subtasks+ When starting on a subtask, first EXPLICITLY SAY which subtask you are working on. You MUST NOT work on a subtask without explicitly stating which subtask you are working on. Say only the name of the subtask. Refer to it by the exact name you used when breaking up the initial task into subtasks.- When starting on a subtask, first EXPLICITLY SAY which subtask you are working on. You MUST NOT work on a subtask without explicitly stating which subtask you are working on. Say only the name of the subtask. Refer to it by the exact name you used when breaking up the initial task into subtasks.+ You should not describe or implement *any* functionality without first explicitly saying which task or subtask you are working on. This is a crucial part of the response and must not be omitted.++ Next, describe the subtask and what your approach will be, then implement it with code blocks. Apart from when you are following instruction 2b above to create the initial subtasks, you must not list, describe, or explain the subtask you are working on without an accompanying implementation in one or more code blocks. Describing what needs to be done to complete a subtask *DOES NOT* count as completing the subtask. It must be fully implemented with code blocks.- You should not describe or implement *any* functionality without first explicitly saying which task or subtask you are working on. This is a crucial part of the response and must not be omitted.-- Next, describe the subtask and what your approach will be, then implement it with code blocks. Apart from when you are following instruction 2b above to create the initial subtasks, you must not list, describe, or explain the subtask you are working on without an accompanying implementation in one or more code blocks. Describing what needs to be done to complete a subtask *DOES NOT* count as completing the subtask. It must be fully implemented with code blocks.+ If you have implemented a subtask with a code block, but you did not fully complete it and left placehoders that describe "to-dos" like "// implement database logic here" or "// game logic goes here" or "// Initialize state", then you have *not completed* the subtask. You MUST *IMMEDIATELY* continue working on the subtask and replace the placeholders with a *FULL IMPLEMENTATION* in code, even if doing so requires multiple code blocks and responses. You MUST NOT leave placeholders in the code blocks.- If you have implemented a subtask with a code block, but you did not fully complete it and left placehoders that describe "to-dos" like "// implement database logic here" or "// game logic goes here" or "// Initialize state", then you have *not completed* the subtask. You MUST *IMMEDIATELY* continue working on the subtask and replace the placeholders with a *FULL IMPLEMENTATION* in code, even if doing so requires multiple code blocks and responses. You MUST NOT leave placeholders in the code blocks.+ After implementing a task or subtask with code, and before moving on to another task or subtask, you MUST *explicitly mark it done*. You can do this by explicitly stating "[subtask] has been completed". For example, "**Adding the update function** has been completed." It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. Never move on to a new subtask. Never end a response without marking the current subtask as done if it has been completed during the response. You MUST NOT omit marking a subtask as done when it has been completed.++ Next, move on to the next task or subtask if any are remaining. Otherwise, if no subtasks are remaining then stop there.++ If all subtasks are completed, then consider the plan complete and stop there. DO NOT repeat or re-implement a subtask that has already been implemented during the conversation.- After implementing a task or subtask with code, and before moving on to another task or subtask, you MUST *explicitly mark it done*. You can do this by explicitly stating "[subtask] has been completed". For example, "**Adding the update function** has been completed." It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. Never move on to a new subtask. Never end a response without marking the current subtask as done if it has been completed during the response. You MUST NOT omit marking a subtask as done when it has been completed.-- Next, move on to the next task or subtask if any are remaining. Otherwise, if no subtasks are remaining then stop there.-- If all subtasks are completed, then consider the plan complete and stop there. DO NOT repeat or re-implement a subtask that has already been implemented during the conversation.+ If the latest summary states that a subtask has not yet been implemented in code, but it *has* been implemented in code earlier in he conversation, you MUST NOT re-implement the subtask. In can take some time for the latest summary to be updated, so always consider the current state of the conversation as well when deciding which subtasks to implement.++ You should only implement each subtask once. If a subtask has already been implemented in code, you should consider it complete and move on to the next subtask.- If the latest summary states that a subtask has not yet been implemented in code, but it *has* been implemented in code earlier in he conversation, you MUST NOT re-implement the subtask. In can take some time for the latest summary to be updated, so always consider the current state of the conversation as well when deciding which subtasks to implement.-- You should only implement each subtask once. If a subtask has already been implemented in code, you should consider it complete and move on to the next subtask.+ You MUST ALWAYS work on subtasks IN ORDER. You must not skip a subtask or work on subtasks out of order. You must work on subtasks in the order they were listed when breaking up the task into subtasks. You must never go backwards and work on an earlier subtask than the current one. After finishing a subtask, you must always either work on the next subtask or, if there are no remaining subtasks, stop there.".- You MUST ALWAYS work on subtasks IN ORDER. You must not skip a subtask or work on subtasks out of order. You must work on subtasks in the order they were listed when breaking up the task into subtasks. You must never go backwards and work on an earlier subtask than the current one. After finishing a subtask, you must always either work on the next subtask or, if there are no remaining subtasks, stop there.".+ ## Things you can't do- ## Things you can't do+ You are able to create and update files, but you are not able to execute code or commands. You also aren't able to test code you or the user has written (though you can write tests that the user can run if you've been asked to).- You are able to create and update files, but you are not able to execute code or commands. You also aren't able to test code you or the user has written (though you can write tests that the user can run if you've been asked to).+ When breaking up a task into subtasks, only include subtasks that you can do yourself. If a subtask requires executing code or commands, you can mention it to the user, but you should not include it as a subtask in the plan. Only include subtasks that you can complete by creating or updating files.- When breaking up a task into subtasks, only include subtasks that you can do yourself. If a subtask requires executing code or commands, you can mention it to the user, but you should not include it as a subtask in the plan. Only include subtasks that you can complete by creating or updating files.+ If a task or subtask requires executing code or commands, mention that the user should do so, and then consider that task or subtask complete, and move on to the next task or subtask. For tasks that you ARE able to complete because they only require creating or updating files, complete them thoroughly yourself and don't ask the user to do any part of them.- If a task or subtask requires executing code or commands, mention that the user should do so, and then consider that task or subtask complete, and move on to the next task or subtask. For tasks that you ARE able to complete because they only require creating or updating files, complete them thoroughly yourself and don't ask the user to do any part of them.+ Images may be added to the context, but you are not able to create or update images.- Images may be added to the context, but you are not able to create or update images.+ ## Use open source libraries when appropriate- ## Use open source libraries when appropriate+ When making a plan and describing each task or subtask, **always consider using open source libraries.** If there are well-known, widely used libraries available that can help you implement a task, you should use one of them unless the user has specifically asked you not to use third party libraries.++ Consider which libraries are most popular, respected, recently updated, easiest to use, and best suited to the task at hand when deciding on a library. Also prefer libraries that have a permissive license.++ Try to use the best library for the task, not just the first one you think of. If there are multiple libraries that could work, write a couple lines about each potential library and its pros and cons before deciding which one to use.++ Don't ask the user which library to use--make the decision yourself. Don't use a library that is very old or unmaintained. Don't use a library that isn't widely used or respected. Don't use a library with a non-permissive license. Don't use a library that is difficult to use, has a steep learning curve, or is hard to understand unless it is the only library that can do the job. Strive for simplicity and ease of use when choosing a libraries.- When making a plan and describing each task or subtask, **always consider using open source libraries.** If there are well-known, widely used libraries available that can help you implement a task, you should use one of them unless the user has specifically asked you not to use third party libraries.-- Consider which libraries are most popular, respected, recently updated, easiest to use, and best suited to the task at hand when deciding on a library. Also prefer libraries that have a permissive license.-- Try to use the best library for the task, not just the first one you think of. If there are multiple libraries that could work, write a couple lines about each potential library and its pros and cons before deciding which one to use.-- Don't ask the user which library to use--make the decision yourself. Don't use a library that is very old or unmaintained. Don't use a library that isn't widely used or respected. Don't use a library with a non-permissive license. Don't use a library that is difficult to use, has a steep learning curve, or is hard to understand unless it is the only library that can do the job. Strive for simplicity and ease of use when choosing a libraries.+ If the user asks you to use a specific library, then use that library.- If the user asks you to use a specific library, then use that library.+ If a task or subtask is small and the implementation is trivial, don't use a library. Just implement the task or subtask directly. Use libraries when they can significantly simplify the task or subtask.- If a task or subtask is small and the implementation is trivial, don't use a library. Just implement the task or subtask directly. Use libraries when they can significantly simplify the task or subtask.+ ## Ending a response- ## Ending a response+ Before ending a response, first mark the current subtask as done as described above if it has been completed during the response.++ At the *very* end of your response, in a final, separate paragraph:- Before ending a response, first mark the current subtask as done as described above if it has been completed during the response.-- At the *very* end of your response, in a final, separate paragraph:+ - If any summaries of the plan have been included in the conversation that list all the subtasks and mark each one 'Implemented' or 'Not implemented', consider only the *latest* summary. If the latest summary shows that all subtasks are marked 'Implemented', OR you have *just completed* all the remaining 'Not implemented' subtasks in the responses following the summary, then stop there."+ Otherwise:+ - If there is a clear next subtask 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 subtask.+ - If the user needs to take some action before you can continue, say so explicitly, 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- - If any summaries of the plan have been included in the conversation that list all the subtasks and mark each one 'Implemented' or 'Not implemented', consider only the *latest* summary. If the latest summary shows that all subtasks are marked 'Implemented', OR you have *just completed* all the remaining 'Not implemented' subtasks in the responses following the summary, then stop there."- Otherwise:- - If there is a clear next subtask 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 subtask.- - If the user needs to take some action before you can continue, say so explicitly, 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+ - Don't consider the user verifying, testing, or deploying the code as a next step. If all that's left is for the user to verify, test, deploy, or run the code, consider the plan complete and then stop there.- - Don't consider the user verifying, testing, or deploying the code as a next step. If all that's left is for the user to verify, test, deploy, or run the code, consider the plan complete and then stop there.+ - It's not up to you to determine whether the plan is finished or not. Another AI will assess the plan and determine if it is complete or not. Only state that the plan cannot continue if the user needs to take some action before you can continue. Don't say it for any other reason. You are *tireless* and will not give up until the plan is complete.- - It's not up to you to determine whether the plan is finished or not. Another AI will assess the plan and determine if it is complete or not. Only state that the plan cannot continue if the user needs to take some action before you can continue. Don't say it for any other reason. You are *tireless* and will not give up until the plan is complete.+ - 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, say so, but remember that you don't have the final word on the matter. Explain why you think the plan is done.+ ## EXTREMELY IMPORTANT Rules for responses- ## EXTREMELY IMPORTANT Rules for responses+ You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next,".- You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next,".+ Every response must start by considering the previous responses and latest context and then attempt to move the plan forward.- Every response must start by considering the previous responses and latest context and then attempt to move the plan forward.+ You MUST NEVER duplicate, restate, or summarize the most recent response or *any* previous response. Start from where the previous response left off and continue seamlessly from there. Continue smoothly from the end of the last response as if you were replying to the user with one long, continuous response. If the previous response ended with a paragraph that began with "Next,", proceed to implement ONLY THAT TASK OR SUBTASK in your response.++ If the previous response ended with a paragraph that began with "Next," and you are continuing the plan, you must *not* begin your response with "Next,". Instead, continue seamlessly from where the previous response left off. If you are not able to complete the task described in the preceding message's "Next," paragraph, you must explicitly describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.++ Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.++ Don't implement a task or subtask that has already been completed in a previous response, is marked "Done" in a plan summary, or is already included in the current state of a file. Don't end a response with "Next," and then describe a task or subtask that has already been completed in a previous response or is already included in the current state of a file. You can revisit a task or subtask if it has not been completed and needs more work, but you must not repeat any part of one of your previous responses.- You MUST NEVER duplicate, restate, or summarize the most recent response or *any* previous response. Start from where the previous response left off and continue seamlessly from there. Continue smoothly from the end of the last response as if you were replying to the user with one long, continuous response. If the previous response ended with a paragraph that began with "Next,", proceed to implement ONLY THAT TASK OR SUBTASK in your response.-- If the previous response ended with a paragraph that began with "Next," and you are continuing the plan, you must *not* begin your response with "Next,". Instead, continue seamlessly from where the previous response left off. If you are not able to complete the task described in the preceding message's "Next," paragraph, you must explicitly describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.-- Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.-- Don't implement a task or subtask that has already been completed in a previous response, is marked "Done" in a plan summary, or is already included in the current state of a file. Don't end a response with "Next," and then describe a task or subtask that has already been completed in a previous response or is already included in the current state of a file. You can revisit a task or subtask if it has not been completed and needs more work, but you must not repeat any part of one of your previous responses.+ DO NOT include "fluffy" additional subtasks when breaking a task up. Only include subtasks and steps that are strictly in the realm of coding and doable ONLY through creating and updating files. Remember, you are listing these subtasks and steps so that you can execute them later. Only list things that YOU can do yourself with NO HELP from the user. Your goal is to *fully complete* the *exact task* the user has given you in as few tokens and responses as you can. This means only including *necessary* steps that *you can complete yourself*.- DO NOT include "fluffy" additional subtasks when breaking a task up. Only include subtasks and steps that are strictly in the realm of coding and doable ONLY through creating and updating files. Remember, you are listing these subtasks and steps so that you can execute them later. Only list things that YOU can do yourself with NO HELP from the user. Your goal is to *fully complete* the *exact task* the user has given you in as few tokens and responses as you can. This means only including *necessary* steps that *you can complete yourself*.+ DO NOT summarize the state of the plan. Another AI will do that. Your job is to move the plan forward, not to summarize it. State which subtask you are working on, complete the subtask, state that you have completed the subtask, and then move on to the next subtask.- DO NOT summarize the state of the plan. Another AI will do that. Your job is to move the plan forward, not to summarize it. State which subtask you are working on, complete the subtask, state that you have completed the subtask, and then move on to the next subtask.+ Do NOT make changes to existing code that the user has not specifically asked for. Implement ONLY the exact changes the user has asked for. Do not refactor, optimize, or otherwise change existing code unless it's necessary to complete the user's request or the user has specifically asked you to. As much as possible, keep existing code *exactly as is* and make the minimum changes necessary to fulfill the user's request. Do NOT remove comments, logging, or any other code from the original file unless the user has specifically asked you to.- Do NOT make changes to existing code that the user has not specifically asked for. Implement ONLY the exact changes the user has asked for. Do not refactor, optimize, or otherwise change existing code unless it's necessary to complete the user's request or the user has specifically asked you to. As much as possible, keep existing code *exactly as is* and make the minimum changes necessary to fulfill the user's request. Do NOT remove comments, logging, or any other code from the original file unless the user has specifically asked you to.+ ## Continuing the plan- ## Continuing the plan+ NEVER repeat any part of your previous response. Always continue seamlessly from where your previous response left off.- NEVER repeat any part of your previous response. Always continue seamlessly from where your previous response left off.+ If the last paragraph of your previous response in the conversation began with "Next," and you are continuing the plan:+ - **ABSOLUTELY DO NOT not repeat any part of your previous response**+ - **ABSOLUTELY DO NOT begin your response with "Next,"**+ - Continue seamlessly from where your previous response left off.+ - Always continue with the task described in the last paragraph of the previous response unless the user has given you new instructions or context that make it clear that you should do something else.+ - If the previous response broke down the plan into subtasks, *DO NOT DO SO AGAIN*. Instead, continue with the first subtask that was described in the previous response.++ ## Consider the latest context- If the last paragraph of your previous response in the conversation began with "Next," and you are continuing the plan:- - **ABSOLUTELY DO NOT not repeat any part of your previous response**- - **ABSOLUTELY DO NOT begin your response with "Next,"**- - Continue seamlessly from where your previous response left off.- - Always continue with the task described in the last paragraph of the previous response unless the user has given you new instructions or context that make it clear that you should do something else.- - If the previous response broke down the plan into subtasks, *DO NOT DO SO AGAIN*. Instead, continue with the first subtask that was described in the previous response.-- ## Consider the latest context+ 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.++ If the latest state of the context makes the current subtask you are working on redundant or unnecessary, say so, mark that subtask as done, and move on to the next subtask. Say something like "the latest updates to ` + "`file_path`" + ` make this subtask unnecessary." I'll mark it as done and move on to the next subtask." and then mark the subtask as done and move on to the next subtask.++ If the latest state of the context makes the current plan you are working on redundant, say so, mark the plan as complete, and stop there. Otherwise, implement the subtask.- 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.-- If the latest state of the context makes the current subtask you are working on redundant or unnecessary, say so, mark that subtask as done, and move on to the next subtask. Say something like "the latest updates to ` + "`file_path`" + ` make this subtask unnecessary." I'll mark it as done and move on to the next subtask." and then mark the subtask as done and move on to the next subtask.-- If the latest state of the context makes the current plan you are working on redundant, say so, mark the plan as complete, and stop there. Otherwise, implement the subtask.+ Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you should always work from the *latest version* of the context when continuing the plan.- Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you should always work from the *latest version* of the context when continuing the plan.+ ## Responding to user questions- ## Responding to user questions-- If a plan is in progress and the user asks you a question, don't respond by continuing with the plan unless that is the clear intention of the question. Instead, respond in chat form and answer the question, then stop there.-- [END OF YOUR INSTRUCTIONS]- `+ If a plan is in progress and the user asks you a question, don't respond by continuing with the plan unless that is the clear intention of the question. Instead, respond in chat form and answer the question, then stop there.++ [END OF YOUR INSTRUCTIONS]+ `var CreateSysMsgNumTokens int@@ -303,7 +303,7 @@ func init() {}const UpdateFormatPrompt = `-You ABSOLUTELY MUST *ONLY* USE the comment "// ... existing code ..." (or the equivalent in another programming language) if you are *updating* an existing file. DO NOT use it when you are creating a new file. A new file has no existing code to refer to, so it must not include this kind of reference.+You ABSOLUTELY MUST *ONLY* USE the comment "// ... existing code ..." (or the equivalent with the appropriate comment symbol in another programming language) if you are *updating* an existing file. DO NOT use it when you are creating a new file. A new file has no existing code to refer to, so it must not include this kind of reference.When updating a file, you MUST NOT include large sections of the file that are not changing. Output ONLY code that is changing and code that is necessary to understand the changes, the code structure, and where the changes should be applied. Example:@@ -312,9 +312,9 @@ When updating a file, you MUST NOT include large sections of the file that are n// ... existing code ...function fooBar() {- // ... existing code ...+ // ... existing code ...- updateState();+ updateState();}// ... existing code ...@@ -327,11 +327,11 @@ ALWAYS show the full structure of where a change should be applied. For example,// ... existing code ...class FooBar {- // ... existing code ...+ // ... existing code ...- updateState() {- doSomething();- }+ updateState() {+ doSomething();+ }}---@@ -342,9 +342,9 @@ Below, if the 'update' function is being added to an existing class, you MUST NO---// ... existing code ...- update() {- doSomething();- }+ update() {+ doSomething();+ }// ... existing code ...---@@ -355,13 +355,491 @@ You ABSOLUTELY MUST include the full code structure like this:// ... existing code ...class FooBar {- // ... existing code ...+ // ... existing code ...- update() {- doSomething();- }+ update() {+ doSomething();+ }}---ALWAYS use the above format when updating a file. You MUST NEVER UNDER ANY CIRCUMSTANCES leave out an "... existing code ..." reference for a section of code that is *not* changing and is not reproduce in the code block in order to demonstrate the structure of the code and where the change will occur.++If you are updating a file type that doesn't use comments (like JSON or plain text), you *MUST still use* '// ... existing code ...' to denote where the reference should be placed. It's ok if // is not a comment in the file type or if these references break the syntax of the file type, since they will be replaced by the correct code from the original file. You MUST still use "// ... existing code ..." references regardless of the file type. Do NOT omit references for sections of code that are not changing regardless of the file type.++For example, in a JSON file:++---++{+ // ... existing code ...++ "foo": "bar",++ "baz": {+ // ... existing code ...++ "arr": [+ // ... existing code ...+ "val"+ ]+ },++ // ... existing code ...+}+---++You MUST NOT omit references in JSON files or similar file types. You MUST NOT leave out "// ... existing code ..." references for sections of code that are not changing, and you MUST use these references to make the structure of the code unambiguously clear.++Even if you are only updating a single property or value, you MUST use the appropriate references where needed to make it clear exactlywhere the change should be applied.++If you have a JSON file like:++---+{+ "name": "vscode-plandex",+ "displayName": "Plandex",+ "description": "VSCode extension for Plandex integration",+ "version": "0.1.0",+ "engines": {+ "vscode": "^1.80.0"+ },+ "categories": [+ "Other"+ ],+ "activationEvents": [+ "onLanguage:plandex"+ ],+ "main": "./dist/extension.js",+ "contributes": {+ "languages": [{+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ }],+ "commands": [+ {+ "command": "plandex.tellPlandex",+ "title": "Tell Plandex"+ }+ ],+ "keybindings": [{+ "command": "plandex.showFilePicker",+ "key": "@",+ "when": "editorTextFocus && editorLangId == plandex"+ }]+ },+ "scripts": {+ "vscode:prepublish": "npm run package",+ "compile": "webpack",+ },+ "devDependencies": {+ "@types/vscode": "^1.80.0",+ "@types/glob": "^8.1.0",+ }+}+---++And you are adding a new key to the 'contributes' object, you MUST NOT output a file block like:++---++{+ "contributes": {+ "languages": [+ {+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"],+ "configuration": "./language-configuration.json"+ }+ ],+ "grammars": [+ {+ "language": "plandex",+ "scopeName": "text.plandex",+ "path": "./syntaxes/plandex.tmLanguage.json",+ "embeddedLanguages": {+ "meta.embedded.block.yaml": "yaml",+ "text.html.markdown": "markdown"+ }+ }+ ]+ }+}++---++The problem with the above is that it leaves out *multiple* reference comments that *MUST* be present. It is EXTREMELY IMPORTANT that you include these references.++You also MUST NOT output a file block like:++---++{+ // ... existing code ...++ "contributes":{+ "languages": [+ {+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"],+ "configuration": "./language-configuration.json"+ }+ ],+ "grammars": [+ {+ "language": "plandex",+ "scopeName": "text.plandex",+ "path": "./syntaxes/plandex.tmLanguage.json",+ "embeddedLanguages": {+ "meta.embedded.block.yaml": "yaml",+ "text.html.markdown": "markdown"+ }+ }+ ]+ }+}++---++This ONLY includes a single reference comment for the code that isn't changing *before* the change. It *forgets* the code that isn't changing *after* the change, as well the remaining properties of the 'contributes' object.++Here's the CORRECT way to output the file block for this change:++---++{+ // ... existing code ...++ "contributes": {+ "languages": [+ {+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"],+ "configuration": "./language-configuration.json"+ }+ ],+ "grammars": [+ {+ "language": "plandex",+ "scopeName": "text.plandex",+ "path": "./syntaxes/plandex.tmLanguage.json",+ "embeddedLanguages": {+ "meta.embedded.block.yaml": "yaml",+ "text.html.markdown": "markdown"+ }+ }+ ],++ // ... existing code ...+ },++ // ... existing code ...+}+---++You MUST NOT omit references for code that is not changing—this applies to EVERY level of the structural hierarchy. No matter how deep the nesting, every level MUST be accounted for with references if it includes code that is not included in the file block and is not changing.++You MUST ONLY use the exact comment "// ... existing code ..." (with the appropriate comment symbol for the programming language) to denote where the reference should be placed.++You MUST NOT use any other form of reference comment. ONLY use "// ... existing code ...".++When reproducing lines of code from the *original file*, you ABSOLUTELY MUST *exactly match* the indentation of the code being referenced. Do NOT alter the indentation of the code being referenced in any way. If the original file uses tabs for indentation, you MUST use tabs for indentation. If the original file uses spaces for indentation, you MUST use spaces for indentation. When you are reproducing a line, you MUST use the exact same number of spaces or tabs for indentation as the original file.++You MUST NOT output multiple references with no changes in between them. DO NOT UNDER ANY CIRCUMSTANCES DO THIS:++---+function fooBar() error {+ log.Println("fooBar")++ // ... existing code ...++ // ... existing code ...++ return nil+}+---++It must instead be:++---+function fooBar() error {+ log.Println("fooBar")++ // ... existing code ...++ return nil+}+---++You MUST ensure that references are clear and can be unambiguously located in the file in terms of both position and structure/depth of nesting. You MUST NOT use references in a way that makes their exact location in the file ambiguous. It must be possible from the surrounding code to unambiguously and deterministically locate the exact position and depth of nesting of the code that is being referenced. Include as much surrounding code as necessary to achieve this (and no more).++For example, if the original file looks like this:++---+const a = [+ 8,+ 9,+ 10,+ 11,+ 12,+ 13,+ 14,+ 15,+]+---++you MUST NOT do this:++---+const a = [+ // ... existing code ...+ 1,+ 5,+ 7,+ // ... existing code ...+]+---++Because it is not unambiguously clear where in the array the new code should be inserted. It could be inserted between any pair of existing elements. The reference comment does not make it clear which, so it is ambiguous.++The correct way to do it is:++---+const a = [+ // ... existing code ...+ 10,+ 1,+ 5,+ 7,+ 11,+ // ... existing code ...+]+---++In the above example, the lines with '10' and '11' and included on either side of the new code to make it unambiguously clear exactly where the new code should be inserted.++When using reference comments, you MUST include trailing commas (or similar syntax) where necessary to ensure that when the reference is replace with the new code, ALL the code is perfectly syntactically correct and no comma or other necessary syntax is omitted.++You MUST NOT do this:++---+const a = [+ 1,+ 5+ // ... existing code ...+]+---++Because it leaves out a necessary trailing comman after the '5'. Instead do this:++---+const a = [+ 1,+ 5,+ // ... existing code ...+]+---++Reference comments MUST ALWAYS be on their *OWN LINES*. You MUST NEVER include a reference comment on the same line as code.++You MUST NOT do this:++---+const a = [1, 2, /* ... existing code ... */, 4, 5]+---++Instead, rewrite the entire line to include the new code without using a reference comment:++---+const a = [1, 2, 11, 15, 14, 4, 5]+---++You MUST NOT extra newlines around a reference comment unless they are also present in the original file. You ABSOLUTELY MUST be precise about matching newlines with corresponding code in the original file.++If the original file looks like this:++---+package main++import (+ "fmt"+ "os"+)++func main() {+ fmt.Println("Hello, World!")+ exec()+ measure()+ os.Exit(0)+}+---++DO NOT output superfluous newlines before or after reference comments like this:++---++// ... existing code ...++func main() {+ fmt.Println("Hello, World!")+ prepareData()++ // ... existing code ...++}++---++Instead, do this:++---+// ... existing code ...++func main() {+ fmt.Println("Hello, World!")+ prepareData()+ // ... existing code ...+}+---++Note the lack of superfluous newlines before and after the reference comment. There is a newline included between the first '// ... existing code ...' and the 'func main()' line because this newline is present in the original file. There is no newline *before* the first '// ... existing code ...' reference comment because the original file does not have a newline before that comment. Similarly, there is no newline before *or* after the second '// ... existing code ...' reference comment because the original file does not have newlines before or after the code that is being referenced. Newlines are SIGNIFICANT—you must strive to maintain consistent formatting between the original file and the changes in the file block.++*++If code is being removed from a file and not replaced with new code, the removal MUST ALWAYS WITHOUT EXCEPTION be shown in a labelled file block according to your instructions. Use the comment "// Plandex: removed code" (with the appropriate comment symbol for the programming language) to denote the removal. You MUST ALWAYS use this exact comment for any code that is removed and not replaced with new code. DO NOT USE ANY OTHER COMMENT FOR CODE REMOVAL.++Do NOT use any other formatting apart from a labelled file block with the comment "// Plandex: removed code" to denote code removal.++Example of code being removed and not replaced with new code:++---+function fooBar() {+ log.Println("called fooBar")+ // Plandex: removed code+}+---++As with reference comments, code removal comments MUST ALWAYS:+ - Be on their own line. They must not be on the same line as any other code.+ - Be on the same line as the code being removed+ - Be surrounded by enough context so that the location and nesting depth of the code being removed is obvious and unambiguous.++Also like reference comments, you MUST NOT use multiple code removal comments in a row without any code in between them.++You MUST NOT do this:++---+function fooBar() {+ // Plandex: removed code+ // Plandex: removed code+ exec()+}+---++Instead, do this:++---+function fooBar() {+ // Plandex: removed code+ exec()+}+---++You MUST NOT use reference comments and removal comments together in an ambiguous way. Do NOT do this:++---+function fooBar() {+ log.Println("called fooBar")+ // Plandex: removed code+ // ... existing code ...+}+---++Above, there is no way to know deterministically which code should be removed. Instead, include context that makes it clear and unambiguous which code should be removed:++---+function fooBar() {+ log.Println("called fooBar")+ // Plandex: removed code+ exec()+ // ... existing code ...+}+---++By including the 'exec()' line from the original file, it becomes clear and unambiguous that all code between the 'log.Println("called fooBar")' line and the 'exec()' line is being removed.++*++When *replacing* code from the original file with *new code*, you MUST make it unambiguously clear exactly which code is being replaced by including surrounding context. Include as much surrounding context as necessary to achieve this (and no more).++If the original file looks like this:++---+class FooBar {+ func baz() {+ log.Println("baz")+ }++ func bar() {+ log.Println("bar")+ sendMessage("bar")+ reportSentMessage()+ }++ func qux() {+ log.Println("qux")+ }++ func axon() {+ log.Println("axon")+ escapeFromBar()+ runAway()+ }++ func tango() {+ log.Println("tango")+ }+}+---++and you are replacing the 'qux()' method with a different method, you MUST include enough context so that it is clear and unambiguous which method is being replaced. Do NOT do this:++---+class FooBar {+ // ... existing code ...++ func updatedQux() {+ log.Println("updatedQux")+ }++ // ... existing code ...+}+---++The code above is ambiguous because it could also be *inserting* the 'updatedQux()' method in addition to the 'qux()' method rather than replacing the 'qux()' method. Instead, include enough context so that it is clear and unambiguous which method is being replaced, like this:++---+class FooBar {+ // ... existing code ...++ func bar() {+ // ... existing code ...+ }++ func updatedQux() {+ log.Println("updatedQux")+ }++ func axon() {+ // ... existing code ...+ }++ // ... existing code ...+}+---++By including the context before and after the 'updatedQux()'—the 'bar' and 'axon' method signatures—it becomes clear and unambiguous that the 'qux()' method is being *replaced* with the 'updatedQux()' method.`diff --git a/app/server/syntax/structural_edits.go b/app/server/syntax/structural_edits.goindex 222efc66..f50912b7 100644--- a/app/server/syntax/structural_edits.go+++ b/app/server/syntax/structural_edits.go@@ -5,6 +5,7 @@ import ("fmt""strings"+ "github.com/davecgh/go-spew/spew"tree_sitter "github.com/smacker/go-tree-sitter")@@ -20,8 +21,9 @@ type TreeSitterSection []*tree_sitter.Nodeconst verboseLogging = true-func ApplyReferences(+func ApplyChanges(ctx context.Context,+ language string,parser *tree_sitter.Parser,original,proposed string,@@ -63,13 +65,15 @@ func ApplyReferences(originalLines := strings.Split(original, "\n")proposedLines := strings.Split(proposed, "\n")- for i, line := range proposedLines {- // keep indentation for syntax parsing- content := strings.TrimSpace(line)- if removalsByLine[Removal(i+1)] {- proposedLines[i] = strings.Replace(line, content, "", 1)- } else if refsByLine[Reference(i+1)] {- proposedLines[i] = strings.Replace(line, content, "", 1)+ if language == "json" {+ for i, line := range proposedLines {+ // keep indentation for syntax parsing+ content := strings.TrimSpace(line)+ if removalsByLine[Removal(i+1)] {+ proposedLines[i] = strings.Replace(line, content, "", 1)+ } else if refsByLine[Reference(i+1)] {+ proposedLines[i] = strings.Replace(line, content, "", 1)+ }}}@@ -90,25 +94,39 @@ func ApplyReferences(}defer proposedTree.Close()- fmt.Printf("anchorLines: %v\n", anchorLines)+ if verboseLogging {+ fmt.Printf("anchorLines: %v\n", anchorLines)+ }++ oRes := buildNodeIndex(originalTree)+ pRes := buildNodeIndex(proposedTree)- originalNodesByLineIndex := buildNodeIndex(originalTree)- proposedNodesByLineIndex := buildNodeIndex(proposedTree)+ originalNodesByLineIndex := oRes.nodesByLine+ proposedNodesByLineIndex := pRes.nodesByLine+ originalParentsByLineIndex := oRes.parentsByLinefindNextAnchor := func(s string, pLineNum int, pNode *tree_sitter.Node, fromLine int) *Anchor {oLineNum, ok := anchorLines[pLineNum]if ok {- fmt.Printf("found anchor in anchorLines: oLineNum: %d, pLineNum: %d\n", oLineNum, pLineNum)+ if verboseLogging {+ fmt.Printf("found anchor in anchorLines: oLineNum: %d, pLineNum: %d\n", oLineNum, pLineNum)+ }oNode := originalNodesByLineIndex[oLineNum-1]- fmt.Printf("oNode.Type(): %s\n", oNode.Type())+ if verboseLogging {+ fmt.Printf("oNode.Type(): %s\n", oNode.Type())+ }anchor := &Anchor{Open: oLineNum, Close: int(oNode.EndPoint().Row) + 1}- fmt.Printf("found anchor: %v\n", anchor)+ if verboseLogging {+ fmt.Printf("found anchor: %v\n", anchor)+ }return anchor} else {- fmt.Printf("no anchor found in anchorLines: pLineNum: %d\n", pLineNum)+ if verboseLogging {+ fmt.Printf("no anchor found in anchorLines: pLineNum: %d\n", pLineNum)+ }}for idx, line := range originalLines {@@ -140,10 +158,12 @@ func ApplyReferences(if stringMatch {var endLineNum intif oNode != nil {- fmt.Printf("oNode.Type(): %s\n", oNode.Type())- fmt.Printf("oNode.EndPoint().Row: %d\n", oNode.EndPoint().Row)- // fmt.Printf("%v\n", oNode)- // fmt.Printf("oNode.Content(originalBytes):\n%q\n", oNode.Content(originalBytes))+ if verboseLogging {+ fmt.Printf("oNode.Type(): %s\n", oNode.Type())+ fmt.Printf("oNode.EndPoint().Row: %d\n", oNode.EndPoint().Row)+ // fmt.Printf("%v\n", oNode)+ // fmt.Printf("oNode.Content(originalBytes):\n%q\n", oNode.Content(originalBytes))+ }endLineNum = int(oNode.EndPoint().Row) + 1}if verboseLogging {@@ -271,7 +291,7 @@ func ApplyReferences(}}- write(strings.Join(fullRef, "\n"), true)+ write(strings.Join(fullRef, "\n"), !eof)postRefContent := postRefBuffers[0].String()@@ -284,12 +304,11 @@ func ApplyReferences(} else {if verboseLogging {fmt.Printf("numRefs > 1, refOriginalParent: %s\n", refOriginalParent.Type())- // fmt.Printf("refOriginalParent.Content(originalBytes):\n%q\n", refOriginalParent.Content(originalBytes))- fmt.Println("original parent type:", refOriginalParent.Type())+ fmt.Printf("refOriginalParent.Content(originalBytes):\n%q\n", refOriginalParent.Content(originalBytes))fmt.Printf("numRefs: %d, oLineNum: %d\n", numRefs, oLineNum)}- sections := getSections(refOriginalParent, originalBytes, numRefs, refStart, oLineNum-1)+ sections := getSections(refOriginalParent, originalBytes, numRefs, refStart, oLineNum)for i, section := range sections {if verboseLogging {@@ -355,13 +374,25 @@ func ApplyReferences(if verboseLogging {fmt.Printf("refNode.Type(): %s\n", refNode.Type())+ fmt.Printf("refNode.Content(originalBytes): %q\n", refNode.Content(originalBytes))++ current := refNode+ depth := 0+ for current != nil {+ fmt.Printf("parent depth %d type: %s content: %q\n",+ depth,+ current.Type(),+ current.Content(originalBytes))+ current = current.Parent()+ depth+++ }}- refOriginalParent = refNode+ refOriginalParent = originalParentsByLineIndex[refStart-1]- // if verboseLogging {- // fmt.Printf("setting refOriginalParent | refNode.Parent() | Type(): %s\n", refOriginalParent.Type())- // }+ if verboseLogging {+ fmt.Printf("setting refOriginalParent | refNode.Parent() | Type(): %s\n", refOriginalParent.Type())+ }} else {refOriginalParent = originalTree.RootNode()@@ -379,7 +410,7 @@ func ApplyReferences(if !refOpen && lastLineMatched && !currentPNodeMatches {if strings.TrimSpace(pLine) == "" {- write(pLine, true)+ write(pLine, !finalLine)if verboseLogging {fmt.Printf("newline, incrementing oLineNum: %d\n", oLineNum)}@@ -531,86 +562,6 @@ func ApplyReferences(return b.String(), nil}-// just using exact string matches for now since there's too much ambiguity in node-based matching-// func nodesMatch(n1, n2 *tree_sitter.Node, source1, source2 []byte) bool {-// // if verboseLogging {-// // fmt.Println("check nodesMatch")-// // }-// if n1 == nil || n2 == nil || !n1.IsNamed() || !n2.IsNamed() {-// // if verboseLogging {-// // fmt.Println("nodes not named")-// // }-// return false-// }--// if n1.Type() != n2.Type() {-// // if verboseLogging {-// // fmt.Println("n1 type != n2 type")-// // }-// return false-// }--// // Find first declaration/definition node-// findDeclNode := func(n *tree_sitter.Node) *tree_sitter.Node {-// cursor := tree_sitter.NewTreeCursor(n)-// defer cursor.Close()--// var findDecl func() *tree_sitter.Node-// findDecl = func() *tree_sitter.Node {-// nodeType := cursor.CurrentNode().Type()-// if strings.HasSuffix(nodeType, "_declaration") ||-// strings.HasSuffix(nodeType, "_definition") ||-// nodeType == "pair" {-// return cursor.CurrentNode()-// }--// if cursor.GoToFirstChild() {-// for {-// if node := findDecl(); node != nil {-// return node-// }-// if !cursor.GoToNextSibling() {-// break-// }-// }-// cursor.GoToParent()-// }-// return nil-// }--// return findDecl()-// }--// decl1 := findDeclNode(n1)-// decl2 := findDeclNode(n2)--// if decl1 == nil || decl2 == nil {-// return false-// }--// // if verboseLogging {-// // fmt.Printf("found declaration nodes of type: %s and %s\n", decl1.Type(), decl2.Type())-// // }--// // Get names from first named child-// name1Node := decl1.NamedChild(0)-// name2Node := decl2.NamedChild(0)--// if name1Node == nil || name2Node == nil ||-// !strings.HasSuffix(name1Node.Type(), "identifier") || !strings.HasSuffix(name2Node.Type(), "identifier") {-// return false-// }--// name1 := name1Node.Content(source1)-// name2 := name2Node.Content(source2)--// // if verboseLogging {-// // fmt.Printf("name1: %s, name2: %s\n", name1, name2)-// // }--// return name1 == name2-// }-func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine, upToLine int) []TreeSitterSection {sections := make([]TreeSitterSection, numSections)structures := [][]*tree_sitter.Node{}@@ -619,19 +570,25 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,cursor := tree_sitter.NewTreeCursor(parent)defer cursor.Close()- firstLineNum := int(parent.StartPoint().Row) + 1+ parentFirstLineNum := int(parent.StartPoint().Row) + 1+ parentEndLineNum := int(parent.EndPoint().Row) + 1if verboseLogging {- fmt.Printf("firstLineNum: %d\n", firstLineNum)+ fmt.Printf("parent.Type(): %s\n", parent.Type())+ fmt.Printf("parent.Content(bytes):\n%q\n", parent.Content(bytes))+ fmt.Printf("parentFirstLineNum: %d\n", parentFirstLineNum)+ fmt.Printf("parentEndLineNum: %d\n", parentEndLineNum)}if cursor.GoToFirstChild() {for {node := cursor.CurrentNode()+startLineNum := int(node.StartPoint().Row) + 1endLineNum := int(node.EndPoint().Row) + 1if verboseLogging {fmt.Printf("startLineNum: %d, endLineNum: %d\n", startLineNum, endLineNum)fmt.Println(node.Type())+ fmt.Printf("node.Content(bytes):\n%q\n", node.Content(bytes))}if startLineNum < fromLine {@@ -644,7 +601,7 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,continue}- if startLineNum == firstLineNum {+ if startLineNum == parentFirstLineNum {if verboseLogging {fmt.Printf("skipping first line\n")}@@ -668,6 +625,10 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,break}+ if endLineNum == parentEndLineNum && !isStructuralNode(node) {+ break+ }+if isStructuralNode(node) {if verboseLogging {fmt.Printf("found structural node: %s\n", node.Type())@@ -693,6 +654,11 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,}}+ if verboseLogging {+ fmt.Printf("structures:\n")+ spew.Dump(structures)+ }+numStructural := len(structures)baseSize := numStructural / numSectionsremainder := numStructural % numSections@@ -725,24 +691,19 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,}if verboseLogging {- // fmt.Printf("sections:\n")- // spew.Dump(sections)+ fmt.Printf("sections:\n")+ spew.Dump(sections)fmt.Println("Sections content:")for i, section := range sections {fmt.Printf("section %d:\n", i)for j, node := range section {fmt.Printf("node %d:\n", j)- // fmt.Println(node.Content(bytes))-- if verboseLogging {- toLog := node.Content(bytes)- if len(toLog) > 200 {- toLog = toLog[:100] + "\n...\n" + toLog[len(toLog)-100:]- }- fmt.Println(toLog)+ toLog := node.Content(bytes)+ if len(toLog) > 200 {+ toLog = toLog[:100] + "\n...\n" + toLog[len(toLog)-100:]}-+ fmt.Println(toLog)}}}@@ -777,8 +738,15 @@ func isStructuralNode(node *tree_sitter.Node) bool {return false}-func buildNodeIndex(tree *tree_sitter.Tree) map[int]*tree_sitter.Node {+type nodeIndex struct {+ nodesByLine map[int]*tree_sitter.Node+ parentsByLine map[int]*tree_sitter.Node+}++func buildNodeIndex(tree *tree_sitter.Tree) *nodeIndex {nodesByLine := make(map[int]*tree_sitter.Node)+ parentsByLine := make(map[int]*tree_sitter.Node)+root := tree.RootNode()// First pass - index direct nodes@@ -796,6 +764,7 @@ func buildNodeIndex(tree *tree_sitter.Tree) map[int]*tree_sitter.Node {node.StartPoint().Column < existing.StartPoint().Column ||(node.StartPoint().Column == existing.StartPoint().Column && depth < getNodeDepth(existing)) {nodesByLine[line] = node+ parentsByLine[line] = node.Parent()}}@@ -836,12 +805,16 @@ func buildNodeIndex(tree *tree_sitter.Tree) map[int]*tree_sitter.Node {nodesByLine[line] = root} else {nodesByLine[line] = parent+ parentsByLine[line] = parent}}}// spew.Dump(nodesByLine)- return nodesByLine+ return &nodeIndex{+ nodesByLine: nodesByLine,+ parentsByLine: parentsByLine,+ }}func getNodeDepth(node *tree_sitter.Node) int {@@ -859,17 +832,38 @@ func (s TreeSitterSection) String(sourceLines []string, bytes []byte) string {return ""}- firstSection := s[0]- startIdx := int(firstSection.StartPoint().Row)+ // Find first structural node+ var firstNode *tree_sitter.Node+ for _, n := range s {+ if isStructuralNode(n) {+ firstNode = n+ break+ }+ }- lastSection := s[len(s)-1]- endIdx := int(lastSection.EndPoint().Row)+ // Find last structural node+ var lastNode *tree_sitter.Node+ for i := len(s) - 1; i >= 0; i-- {+ if isStructuralNode(s[i]) {+ lastNode = s[i]+ break+ }+ }++ startIdx := int(firstNode.StartPoint().Row)+ endIdx := int(lastNode.EndPoint().Row)if verboseLogging {+ for _, node := range s {+ fmt.Printf("node.Type(): %s\n", node.Type())+ fmt.Printf("StartPoint().Row: %d\n", node.StartPoint().Row)+ fmt.Printf("EndPoint().Row: %d\n", node.EndPoint().Row)+ }+fmt.Printf("section.String startIdx: %d, endIdx: %d\n", startIdx, endIdx)}- parent := lastSection.Parent()+ parent := lastNode.Parent()parentEndNode := parent.Child(int(parent.ChildCount()) - 1)lastLine := sourceLines[endIdx]if lastLine == parentEndNode.Content(bytes) {diff --git a/app/server/syntax/structural_edits_test.go b/app/server/syntax/structural_edits_test.goindex d6ae8c9f..67ef7b88 100644--- a/app/server/syntax/structural_edits_test.go+++ b/app/server/syntax/structural_edits_test.go@@ -17,669 +17,895 @@ func TestStructuralReplacements(t *testing.T) {references []Referenceremovals []Removalwant string+ language stringparser *tree_sitter.ParseranchorLines map[int]int}{{name: "single reference in function",original: `- func processUser(id int) error {- validate(id)- startTx()- updateUser(id)- commit()- return nil- }`,+ func processUser(id int) error {+ validate(id)+ startTx()+ updateUser(id)+ commit()+ return nil+ }`,proposed: `- func processUser(id int) error {- // ... existing code ...- log.Info("processing user")- return nil- }`,+ func processUser(id int) error {+ // ... existing code ...+ log.Info("processing user")+ return nil+ }`,references: []Reference{3,},want: `- func processUser(id int) error {- validate(id)- startTx()- updateUser(id)- commit()- log.Info("processing user")- return nil- }`,- parser: getParserForLanguage("go"),+ func processUser(id int) error {+ validate(id)+ startTx()+ updateUser(id)+ commit()+ log.Info("processing user")+ return nil+ }`,+ language: "go",+ parser: getParserForLanguage("go"),},- // no longer intending to handle modified function signatures- // {- // name: "modified function signature, ref at end of function",- // original: `- // func processUser(id int) error {- // validate(id)- // validateAgain(id)- // prepForUpdate(id)- // return update(id)- // }`,- // proposed: `- // func processUser(id int, force bool) (error, bool) {- // if force {- // log.Warn("will force update")- // }- // // ... existing code ...- // }`,- // references: []Reference{- // 6,- // },- // want: `- // func processUser(id int, force bool) (error, bool) {- // if force {- // log.Warn("will force update")- // }- // validate(id)- // validateAgain(id)- // prepForUpdate(id)- // return update(id)- // }`,- // parser: getParserForLanguage("go"),- // },- // {- // name: "modified function signature, ref at beginning of function",- // original: `- // func processUser(id int) error {- // validate(id)- // validateAgain(id)- // prepForUpdate(id)- // return update(id)- // }`,- // proposed: `- // func processUser(id int, force bool) (error, bool) {- // // ... existing code ...- // if force {- // log.Warn("will force update")- // }- // return update(id)- // }`,- // references: []Reference{- // 3,- // },- // want: `- // func processUser(id int, force bool) (error, bool) {- // validate(id)- // validateAgain(id)- // prepForUpdate(id)- // if force {- // log.Warn("will force update")- // }- // return update(id)- // }`,- // parser: getParserForLanguage("go"),- // },{name: "bad formatting",original: `- func processUser(id int) error {- validate(id)- validateAgain(id)- prepForUpdate(id)- return update(id)- }`,+ func processUser(id int) error {+ validate(id)+ validateAgain(id)+ prepForUpdate(id)+ return update(id)+ }`,proposed: `- func processUser(id int) error {- // ... existing code ...- if force {- log.Warn("will force update")- }- return update(id)- }`,+ func processUser(id int) error {+ // ... existing code ...+ if force {+ log.Warn("will force update")+ }+ return update(id)+ }`,references: []Reference{3,},want: `- func processUser(id int) error {- validate(id)- validateAgain(id)- prepForUpdate(id)- if force {- log.Warn("will force update")- }- return update(id)- }`,- parser: getParserForLanguage("go"),+ func processUser(id int) error {+ validate(id)+ validateAgain(id)+ prepForUpdate(id)+ if force {+ log.Warn("will force update")+ }+ return update(id)+ }`,+ language: "go",+ parser: getParserForLanguage("go"),},{name: "multiple refs in class/nested structures",original: `- package main+ package main- import "log"-- func init() {- log.Println("init")- }-- type UserService struct {- db *DB- cache *Cache- }-- func (s *UserService) Process() {- s.validate()- s.update()- s.notify()- }-- func (s *UserService) Update() {- s.db.begin()- s.db.exec()- s.db.commit()- }-- func (s *UserService) Record() {- log.Println("record")- }- `,+ import "log"++ func init() {+ log.Println("init")+ }++ type UserService struct {+ db *DB+ cache *Cache+ }++ func (s *UserService) Process() {+ s.validate()+ s.update()+ s.notify()+ }++ func (s *UserService) Update() {+ s.db.begin()+ s.db.exec()+ s.db.commit()+ }++ func (s *UserService) Record() {+ log.Println("record")+ }+ `,proposed: `- // ... existing code ...+ // ... existing code ...- type UserService struct {- // ... existing fields ...- metrics *Metrics- }+ type UserService struct {+ // ... existing code ...+ metrics *Metrics+ }- func (s *UserService) Process() {- // ... existing validation ...- s.metrics.Record()- // ... existing processing ...- }+ func (s *UserService) Process() {+ // ... existing code ...+ s.metrics.Record()+ // ... existing code ...+ }- func (s *UserService) Update() {- // ... existing code ...- }+ func (s *UserService) Update() {+ // ... existing code ...+ }- // ... existing code ...- `,+ // ... existing code ...+ `,references: []Reference{2, 5, 10, 12, 16, 19,},want: `- package main+ package main- import "log"-- func init() {- log.Println("init")- }-- type UserService struct {- db *DB- cache *Cache- metrics *Metrics- }-- func (s *UserService) Process() {- s.validate()- s.update()- s.metrics.Record()- s.notify()- }-- func (s *UserService) Update() {- s.db.begin()- s.db.exec()- s.db.commit()- }-- func (s *UserService) Record() {- log.Println("record")- }- `,- parser: getParserForLanguage("go"),+ import "log"++ func init() {+ log.Println("init")+ }++ type UserService struct {+ db *DB+ cache *Cache+ metrics *Metrics+ }++ func (s *UserService) Process() {+ s.validate()+ s.update()+ s.metrics.Record()+ s.notify()+ }++ func (s *UserService) Update() {+ s.db.begin()+ s.db.exec()+ s.db.commit()+ }++ func (s *UserService) Record() {+ log.Println("record")+ }+ `,+ language: "go",+ parser: getParserForLanguage("go"),},{name: "code removal comment",original: `- func processUser(id int) error {- validate(id)- startTx()- logTransaction()- validateAgain(id)- updateUser(id)- commit()- return nil- }`,+ func processUser(id int) error {+ validate(id)+ startTx()+ logTransaction()+ validateAgain(id)+ updateUser(id)+ commit()+ return nil+ }`,proposed: `- func processUser(id int) error {- validate(id)- // Plandex: removed code- validateAgain(id)- updateUser(id)- commit()- return nil- }`,+ func processUser(id int) error {+ validate(id)+ // Plandex: removed code+ validateAgain(id)+ updateUser(id)+ commit()+ return nil+ }`,removals: []Removal{4,},want: `- func processUser(id int) error {- validate(id)- validateAgain(id)- updateUser(id)- commit()- return nil- }`,- parser: getParserForLanguage("go"),+ func processUser(id int) error {+ validate(id)+ validateAgain(id)+ updateUser(id)+ commit()+ return nil+ }`,+ language: "go",+ parser: getParserForLanguage("go"),},{name: "multiple code removal comments",original: `- func processUser(id int) error {- validate(id)- startTx()- logTransaction()- validateAgain(id)- logValidation()- updateUser(id)- commit()- return nil- }`,+ func processUser(id int) error {+ validate(id)+ startTx()+ logTransaction()+ validateAgain(id)+ logValidation()+ updateUser(id)+ commit()+ return nil+ }`,proposed: `- func processUser(id int) error {- validate(id)- // Plandex: removed code- validateAgain(id)- // Plandex: removed code- updateUser(id)- commit()- return nil- }`,+ func processUser(id int) error {+ validate(id)+ // Plandex: removed code+ validateAgain(id)+ // Plandex: removed code+ updateUser(id)+ commit()+ return nil+ }`,removals: []Removal{4, 6,},want: `- func processUser(id int) error {- validate(id)- validateAgain(id)- updateUser(id)- commit()- return nil- }`,- parser: getParserForLanguage("go"),+ func processUser(id int) error {+ validate(id)+ validateAgain(id)+ updateUser(id)+ commit()+ return nil+ }`,+ language: "go",+ parser: getParserForLanguage("go"),},{name: "json update with reference comments",original: `{- "name": "test-app",- "version": "1.0.0",- "dependencies": {- "express": "^4.17.1",- "body-parser": "^1.19.0",- "cors": "^2.8.5"- },- "scripts": {- "start": "node index.js",- "test": "jest",- "build": "webpack"- }- }`,+ "name": "test-app",+ "version": "1.0.0",+ "dependencies": {+ "express": "^4.17.1",+ "body-parser": "^1.19.0",+ "cors": "^2.8.5"+ },+ "scripts": {+ "start": "node index.js",+ "test": "jest",+ "build": "webpack"+ }+ }`,proposed: `{- // ... existing code ...- "dependencies": {- "express": "^4.17.1",- "body-parser": "^1.19.0",- "cors": "^2.8.5",- "dotenv": "^16.0.0",- "mongoose": "^6.0.0"- },- // ... existing code ...- }`,+ // ... existing code ...+ "dependencies": {+ "express": "^4.17.1",+ "body-parser": "^1.19.0",+ "cors": "^2.8.5",+ "dotenv": "^16.0.0",+ "mongoose": "^6.0.0"+ },+ // ... existing code ...+ }`,references: []Reference{2, 10,},want: `{- "name": "test-app",- "version": "1.0.0",- "dependencies": {- "express": "^4.17.1",- "body-parser": "^1.19.0",- "cors": "^2.8.5",- "dotenv": "^16.0.0",- "mongoose": "^6.0.0"- },- "scripts": {- "start": "node index.js",- "test": "jest",- "build": "webpack"- }- }`,- parser: getParserForLanguage("json"),+ "name": "test-app",+ "version": "1.0.0",+ "dependencies": {+ "express": "^4.17.1",+ "body-parser": "^1.19.0",+ "cors": "^2.8.5",+ "dotenv": "^16.0.0",+ "mongoose": "^6.0.0"+ },+ "scripts": {+ "start": "node index.js",+ "test": "jest",+ "build": "webpack"+ }+ }`,+ language: "json",+ parser: getParserForLanguage("json"),},- // {- // name: "array update with context",- // original: `- // const config = {- // ports: [3000, 3001, 3002, 3003],- // hosts: ["localhost", "127.0.0.1"],- // timeouts: [1000, 2000, 5000]- // }`,- // proposed: `- // const config = {- // ports: [3000, 3001, 8080, 8081, 3002, 3003],- // hosts: ["localhost", "127.0.0.1"],- // // ... existing code ...- // }`,- // references: []Reference{- // 4,- // },- // want: `- // const config = {- // ports: [3000, 3001, 8080, 8081, 3002, 3003],- // hosts: ["localhost", "127.0.0.1"],- // timeouts: [1000, 2000, 5000]- // }`,- // parser: getParserForLanguage("javascript"),- // },{name: "method replacement with context",original: `- class UserService {- constructor() {- this.cache = new Cache()- }-- async getUser(id) {- const user = await db.find(id)- return user- }-- async updateUser(id, data) {- await db.update(id, data)- this.cache.clear()- }-- async deleteUser(id) {- await db.delete(id)- this.cache.clear()- }- }`,+ class UserService {+ constructor() {+ this.cache = new Cache()+ }++ async getUser(id) {+ const user = await db.find(id)+ return user+ }++ async updateUser(id, data) {+ await db.update(id, data)+ this.cache.clear()+ }++ async deleteUser(id) {+ await db.delete(id)+ this.cache.clear()+ }+ }`,proposed: `- class UserService {- // ... existing code ...-- async getUser(id) {- const cached = await this.cache.get(id)- if (cached) return cached-- const user = await db.find(id)- await this.cache.set(id, user)- return user- }-- // ... existing code ...- }`,+ class UserService {+ // ... existing code ...++ async getUser(id) {+ const cached = await this.cache.get(id)+ if (cached) return cached++ const user = await db.find(id)+ await this.cache.set(id, user)+ return user+ }++ // ... existing code ...+ }`,references: []Reference{3, 14,},want: `- class UserService {- constructor() {- this.cache = new Cache()- }-- async getUser(id) {- const cached = await this.cache.get(id)- if (cached) return cached-- const user = await db.find(id)- await this.cache.set(id, user)- return user- }-- async updateUser(id, data) {- await db.update(id, data)- this.cache.clear()- }-- async deleteUser(id) {- await db.delete(id)- this.cache.clear()- }- }`,- parser: getParserForLanguage("javascript"),+ class UserService {+ constructor() {+ this.cache = new Cache()+ }++ async getUser(id) {+ const cached = await this.cache.get(id)+ if (cached) return cached++ const user = await db.find(id)+ await this.cache.set(id, user)+ return user+ }+++ async updateUser(id, data) {+ await db.update(id, data)+ this.cache.clear()+ }++ async deleteUser(id) {+ await db.delete(id)+ this.cache.clear()+ }+ }`,+ language: "javascript",+ parser: getParserForLanguage("javascript"),},{name: "nested class methods update",original: `- namespace Database {- class Transaction {- begin() {- log.Info("beginning transaction")- startTx()- }-- commit() {- log.Info("committing transaction")- commitTx()- }-- rollback() {- log.Info("rolling back transaction")- rollbackTx()- }- }- }`,+ namespace Database {+ class Transaction {+ begin() {+ log.Info("beginning transaction")+ startTx()+ }++ commit() {+ log.Info("committing transaction")+ commitTx()+ }++ rollback() {+ log.Info("rolling back transaction")+ rollbackTx()+ }+ }+ }`,proposed: `- namespace Database {- class Transaction {- begin() {- // ... existing code ...- }-- commit() {- log.Info("committing transaction")- validateTx()- commitTx()- notifyCommit()- }-- // ... existing code ...- }- }`,+ namespace Database {+ class Transaction {+ begin() {+ // ... existing code ...+ }++ commit() {+ log.Info("committing transaction")+ validateTx()+ commitTx()+ notifyCommit()+ }++ // ... existing code ...+ }+ }`,references: []Reference{5, 15,},want: `- namespace Database {- class Transaction {- begin() {- log.Info("beginning transaction")- startTx()- }-- commit() {- log.Info("committing transaction")- validateTx()- commitTx()- notifyCommit()- }-- rollback() {- log.Info("rolling back transaction")- rollbackTx()- }- }- }`,- parser: getParserForLanguage("typescript"),+ namespace Database {+ class Transaction {+ begin() {+ log.Info("beginning transaction")+ startTx()+ }++ commit() {+ log.Info("committing transaction")+ validateTx()+ commitTx()+ notifyCommit()+ }+++ rollback() {+ log.Info("rolling back transaction")+ rollbackTx()+ }+ }+ }`,+ language: "typescript",+ parser: getParserForLanguage("typescript"),},{name: "update with trailing commas",original: `- const handlers = {- onStart: () => {- console.log("starting")- },- onProcess: () => {- console.log("processing")- },- onFinish: () => {- console.log("finishing")- },- }`,+ const handlers = {+ onStart: () => {+ console.log("starting")+ },+ onProcess: () => {+ console.log("processing")+ },+ onFinish: () => {+ console.log("finishing")+ },+ }`,proposed: `- const handlers = {- // ... existing code ...- onProcess: () => {- console.log("processing")- emitEvent("process"),- },- // ... existing code ...- }`,+ const handlers = {+ // ... existing code ...+ onProcess: () => {+ console.log("processing")+ emitEvent("process"),+ },+ // ... existing code ...+ }`,references: []Reference{3, 8,},want: `- const handlers = {- onStart: () => {- console.log("starting")- },- onProcess: () => {- console.log("processing")- emitEvent("process"),- },- onFinish: () => {- console.log("finishing")- },- }`,- parser: getParserForLanguage("javascript"),+ const handlers = {+ onStart: () => {+ console.log("starting")+ },+ onProcess: () => {+ console.log("processing")+ emitEvent("process"),+ },+ onFinish: () => {+ console.log("finishing")+ },+ }`,+ language: "javascript",+ parser: getParserForLanguage("javascript"),},{name: "multiple structural updates",original: `- class Logger {- info(msg) {- console.log("[INFO]", msg)- }-- warn(msg) {- console.log("[WARN]", msg)- }-- error(msg) {- console.log("[ERROR]", msg)- }-- debug(msg) {- console.log("[DEBUG]", msg)- }- }`,+ class Logger {+ info(msg) {+ console.log("[INFO]", msg)+ }++ warn(msg) {+ console.log("[WARN]", msg)+ }++ error(msg) {+ console.log("[ERROR]", msg)+ }++ debug(msg) {+ console.log("[DEBUG]", msg)+ }+ }`,proposed: `- class Logger {- constructor(prefix) {- this.prefix = prefix- }+ class Logger {+ constructor(prefix) {+ this.prefix = prefix+ }- info(msg) {- console.log(this.prefix, "[INFO]", msg)- }+ info(msg) {+ console.log(this.prefix, "[INFO]", msg)+ }- // ... existing code ...+ // ... existing code ...- error(msg) {- console.error(this.prefix, "[ERROR]", msg)- notify("error", msg)- }+ error(msg) {+ console.error(this.prefix, "[ERROR]", msg)+ notify("error", msg)+ }- // ... existing code ...+ // ... existing code ...- fatal(msg) {- console.error(this.prefix, "[FATAL]", msg)- process.exit(1)- }- }`,+ fatal(msg) {+ console.error(this.prefix, "[FATAL]", msg)+ process.exit(1)+ }+ }`,references: []Reference{11, 18,},want: `- class Logger {- constructor(prefix) {- this.prefix = prefix- }-- info(msg) {- console.log(this.prefix, "[INFO]", msg)- }-- warn(msg) {- console.log("[WARN]", msg)- }-- error(msg) {- console.error(this.prefix, "[ERROR]", msg)- notify("error", msg)- }-- debug(msg) {- console.log("[DEBUG]", msg)- }-- fatal(msg) {- console.error(this.prefix, "[FATAL]", msg)- process.exit(1)- }- }`,- parser: getParserForLanguage("javascript"),+ class Logger {+ constructor(prefix) {+ this.prefix = prefix+ }++ info(msg) {+ console.log(this.prefix, "[INFO]", msg)+ }++ warn(msg) {+ console.log("[WARN]", msg)+ }++ error(msg) {+ console.error(this.prefix, "[ERROR]", msg)+ notify("error", msg)+ }++ debug(msg) {+ console.log("[DEBUG]", msg)+ }++ fatal(msg) {+ console.error(this.prefix, "[FATAL]", msg)+ process.exit(1)+ }+ }`,+ language: "javascript",+ parser: getParserForLanguage("javascript"),},{name: "updated variable assignment",original: `- import logger from "logger";+ import logger from "logger";- const a = 1;- const b = 2;- const c = 3;- `,+ const a = 1;+ const b = 2;+ const c = 3;+ `,proposed: `- // ... existing code ...+ // ... existing code ...++ const a = 10;+ const b = 2;+ // ... existing code ...+ `,+ references: []Reference{2, 6},+ anchorLines: map[int]int{4: 4},+ want: `+ import logger from "logger";++ const a = 10;+ const b = 2;+ const c = 3;+ `,+ language: "javascript",+ parser: getParserForLanguage("javascript"),+ },- const a = 10;- const b = 2;- // ... existing code ...- `,- references: []Reference{3},+ {+ name: "json multi-level update",+ original: `+{+ "name": "vscode-plandex",+ "displayName": "Plandex",+ "description": "VSCode extension for Plandex integration",+ "version": "0.1.0",+ "engines": {+ "vscode": "^1.80.0"+ },+ "categories": [+ "Other"+ ],+ "activationEvents": [+ "onLanguage:plandex"+ ],+ "main": "./dist/extension.js",+ "contributes": {+ "languages": [{+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"]+ }],+ "commands": [+ {+ "command": "plandex.tellPlandex",+ "title": "Tell Plandex"+ }+ ],+ "keybindings": [{+ "command": "plandex.showFilePicker",+ "key": "@",+ "when": "editorTextFocus && editorLangId == plandex"+ }]+ },+ "scripts": {+ "vscode:prepublish": "npm run package",+ "compile": "webpack",+ "watch": "webpack --watch",+ "package": "webpack --mode production --devtool hidden-source-map",+ "compile-tests": "tsc -p . --outDir out",+ "watch-tests": "tsc -p . -w --outDir out",+ "test": "node ./out/test/runTest.js"+ },+ "devDependencies": {+ "@types/vscode": "^1.80.0",+ "@types/glob": "^8.1.0",+ "@types/mocha": "^10.0.1",+ "@types/node": "20.2.5",+ "@typescript-eslint/eslint-plugin": "^5.59.8",+ "@typescript-eslint/parser": "^5.59.8",+ "eslint": "^8.41.0",+ "glob": "^8.1.0",+ "mocha": "^10.2.0",+ "typescript": "^5.1.3",+ "ts-loader": "^9.4.3",+ "webpack": "^5.85.0",+ "webpack-cli": "^5.1.1",+ "@vscode/test-electron": "^2.3.2"+ }+}+`,+ proposed: `+{+ // ... existing code ...+ "contributes": {+ "languages": [{+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"],+ "configuration": "./language-configuration.json",+ "icon": {+ "light": "./icons/plandex-light.png",+ "dark": "./icons/plandex-dark.png"+ }+ }],+ "grammars": [{+ "language": "plandex",+ "scopeName": "text.plandex",+ "path": "./syntaxes/plandex.tmLanguage.json",+ "embeddedLanguages": {+ "meta.embedded.block.yaml": "yaml",+ "text.html.markdown": "markdown"+ }+ }],+ // ... existing code ...+ },+ // ... existing code ...+}+`,want: `- import logger from "logger";+{+ "name": "vscode-plandex",+ "displayName": "Plandex",+ "description": "VSCode extension for Plandex integration",+ "version": "0.1.0",+ "engines": {+ "vscode": "^1.80.0"+ },+ "categories": [+ "Other"+ ],+ "activationEvents": [+ "onLanguage:plandex"+ ],+ "main": "./dist/extension.js",+ "contributes": {+ "languages": [{+ "id": "plandex",+ "aliases": ["Plandex", "plandex"],+ "extensions": [".pd"],+ "configuration": "./language-configuration.json",+ "icon": {+ "light": "./icons/plandex-light.png",+ "dark": "./icons/plandex-dark.png"+ }+ }],+ "grammars": [{+ "language": "plandex",+ "scopeName": "text.plandex",+ "path": "./syntaxes/plandex.tmLanguage.json",+ "embeddedLanguages": {+ "meta.embedded.block.yaml": "yaml",+ "text.html.markdown": "markdown"+ }+ }],+ "commands": [+ {+ "command": "plandex.tellPlandex",+ "title": "Tell Plandex"+ }+ ],+ "keybindings": [{+ "command": "plandex.showFilePicker",+ "key": "@",+ "when": "editorTextFocus && editorLangId == plandex"+ }]+ },+ "scripts": {+ "vscode:prepublish": "npm run package",+ "compile": "webpack",+ "watch": "webpack --watch",+ "package": "webpack --mode production --devtool hidden-source-map",+ "compile-tests": "tsc -p . --outDir out",+ "watch-tests": "tsc -p . -w --outDir out",+ "test": "node ./out/test/runTest.js"+ },+ "devDependencies": {+ "@types/vscode": "^1.80.0",+ "@types/glob": "^8.1.0",+ "@types/mocha": "^10.0.1",+ "@types/node": "20.2.5",+ "@typescript-eslint/eslint-plugin": "^5.59.8",+ "@typescript-eslint/parser": "^5.59.8",+ "eslint": "^8.41.0",+ "glob": "^8.1.0",+ "mocha": "^10.2.0",+ "typescript": "^5.1.3",+ "ts-loader": "^9.4.3",+ "webpack": "^5.85.0",+ "webpack-cli": "^5.1.1",+ "@vscode/test-electron": "^2.3.2"+ }+}+`,+ language: "json",+ parser: getParserForLanguage("json"),+ references: []Reference{+ 3, 24, 26,+ },+ },+ {+ name: "scala complex structures",+ original: `+package domain.service++import java.time.format.DateTimeFormatter++class MetricsService(+ client: Client,+ service: Service,+ automation: Automation+)(+ implicit context: Context+) extends LazyLogging+ with BaseImplicits {++ def metrics(+ ids: Seq[Id],+ channels: Option[Seq[Channel]],+ ): Future[Metrics] = {++ getMetrics(+ ids,+ channels,+ Endpoint.Metrics+ )+ }++ def metrics2(+ ids: Seq[Id],+ channels: Option[Seq[Channel]],+ ): Future[Metrics] = {++ getMetrics2(+ ids,+ channels,+ Endpoint.Metrics+ )+ }+ }+`,- const a = 10;- const b = 2;- const c = 3;- `,- parser: getParserForLanguage("javascript"),+ proposed: `+package domain.service++// ... existing code ...++class MetricsService(+ // ... existing code ...+)(+ implicit context: Context+) extends LazyLogging+ with BaseImplicits {++ // ... existing code ...++ def update(authContext: AuthContext, id: String): Future[Done] = {+ fallbacks.stub+ .update(+ updateRequest(+ authContext = Some(authContext),+ id = id+ )+ )+ .map(_ => Done)+ }++ // ... existing code ...+ }+`,++ want: `+package domain.service++import java.time.format.DateTimeFormatter++class MetricsService(+ client: Client,+ service: Service,+ automation: Automation+)(+ implicit context: Context+) extends LazyLogging+ with BaseImplicits {++ def metrics(+ ids: Seq[Id],+ channels: Option[Seq[Channel]],+ ): Future[Metrics] = {++ getMetrics(+ ids,+ channels,+ Endpoint.Metrics+ )+ }++ def update(authContext: AuthContext, id: String): Future[Done] = {+ fallbacks.stub+ .update(+ updateRequest(+ authContext = Some(authContext),+ id = id+ )+ )+ .map(_ => Done)+ }++ def metrics2(+ ids: Seq[Id],+ channels: Option[Seq[Channel]],+ ): Future[Metrics] = {++ getMetrics2(+ ids,+ channels,+ Endpoint.Metrics+ )+ }+ }+`,+ references: []Reference{+ 4, 7, 13, 26,+ },+ parser: getParserForLanguage("scala"),},}for _, tt := range tests {- if tt.name == "array update with context" {- t.Run(tt.name, func(t *testing.T) {- anchorLines := map[int]int{}- if tt.anchorLines != nil {- anchorLines = tt.anchorLines- }-- got, err := ApplyReferences(- context.Background(),- tt.parser,- tt.original,- tt.proposed,- tt.references,- tt.removals,- anchorLines,- )- fmt.Println()- fmt.Println(tt.name)- fmt.Println(got)- fmt.Println()- assert.NoError(t, err)- assert.Equal(t, tt.want, got)- })- }+ // if tt.name == "scala complex structures" {+ t.Run(tt.name, func(t *testing.T) {+ anchorLines := map[int]int{}+ if tt.anchorLines != nil {+ anchorLines = tt.anchorLines+ }++ got, err := ApplyChanges(+ context.Background(),+ tt.language,+ tt.parser,+ tt.original,+ tt.proposed,+ tt.references,+ tt.removals,+ anchorLines,+ )+ fmt.Println()+ fmt.Println(tt.name)+ fmt.Println(got)+ fmt.Println()+ assert.NoError(t, err)+ assert.Equal(t, tt.want, got)+ })+ // }}}diff --git a/app/shared/data_models.go b/app/shared/data_models.goindex 524febe1..8f4312d6 100644--- a/app/shared/data_models.go+++ b/app/shared/data_models.go@@ -155,6 +155,7 @@ type PlanBuild struct {type Replacement struct {Id string `json:"id"`Old string `json:"old"`+ Summary string `json:"summary"`EntireFile bool `json:"entireFile"`New string `json:"new"`Failed bool `json:"failed"`@@ -163,6 +164,16 @@ type Replacement struct {StreamedChangeUpdated *StreamedChangeWithLineNumsUpdated `json:"streamedChangeUpdated"`}+func (r *Replacement) GetSummary() string {+ if r.Summary != "" {+ return r.Summary+ }+ if r.StreamedChange != nil {+ return r.StreamedChange.Summary+ }+ return ""+}+type PlanFileResult struct {Id string `json:"id"`TypeVersion int `json:"typeVersion"`