Skip to content

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

default to claude+gpt-4o model pack, use claude for builder with expand references strategy

Dane Schneiderd05a7956e321
diff --git a/app/server/db/diff_helpers.go b/app/server/db/diff_helpers.go
index 8a3c7101..ad9e114b 100644
--- a/app/server/db/diff_helpers.go
+++ b/app/server/db/diff_helpers.go
@@ -1,12 +1,16 @@
package db
import (
+ "bufio"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
+ "strconv"
+ "strings"
+ "github.com/google/uuid"
"github.com/plandex/plandex/shared"
)
@@ -173,3 +177,103 @@ func GetDiffs(original, updated string) (string, error) {
return string(res), nil
}
+
+type change struct {
+ Old string
+ New string
+ Line int
+ Length int
+}
+
+func GetDiffReplacements(original, updated string) ([]*shared.Replacement, error) {
+ diff, err := GetDiffs(original, updated)
+ if err != nil {
+ return nil, fmt.Errorf("error getting git diffs: %v", err)
+ }
+
+ var changes []*change
+ scanner := bufio.NewScanner(strings.NewReader(diff))
+
+ var currentHunk *change
+ var oldLines, newLines []string
+
+ for scanner.Scan() {
+ line := scanner.Text()
+
+ // Parse hunk header
+ if strings.HasPrefix(line, "@@") {
+ // If we have a previous hunk, process it
+ if currentHunk != nil {
+ change := processHunk(oldLines, newLines, currentHunk.Line)
+ if change != nil {
+ changes = append(changes, change)
+ }
+ }
+
+ // Parse the new hunk header
+ lineInfo := strings.Split(line, " ")[1:] // Skip @@ part
+ oldInfo := strings.Split(lineInfo[0], ",")
+ startLine, _ := strconv.Atoi(strings.TrimPrefix(oldInfo[0], "-"))
+
+ currentHunk = &change{
+ Line: startLine,
+ }
+ oldLines = []string{}
+ newLines = []string{}
+ continue
+ }
+
+ if currentHunk == nil {
+ continue // Skip until we find a hunk
+ }
+
+ // Process the lines within a hunk
+ switch {
+ case strings.HasPrefix(line, "-"):
+ oldLines = append(oldLines, strings.TrimPrefix(line, "-"))
+ case strings.HasPrefix(line, "+"):
+ newLines = append(newLines, strings.TrimPrefix(line, "+"))
+ case strings.HasPrefix(line, " "):
+ // Context lines - add to both
+ line = strings.TrimPrefix(line, " ")
+ oldLines = append(oldLines, line)
+ newLines = append(newLines, line)
+ }
+ }
+
+ if err := scanner.Err(); err != nil {
+ return nil, fmt.Errorf("error scanning diff: %v", err)
+ }
+
+ // Process the last hunk if exists
+ if currentHunk != nil {
+ change := processHunk(oldLines, newLines, currentHunk.Line)
+ if change != nil {
+ changes = append(changes, change)
+ }
+ }
+
+ replacements := make([]*shared.Replacement, len(changes))
+ for i, change := range changes {
+ replacements[i] = &shared.Replacement{
+ Id: uuid.New().String(),
+ Old: change.Old,
+ New: change.New,
+ }
+ }
+
+ return replacements, nil
+}
+
+func processHunk(oldLines, newLines []string, startLine int) *change {
+ if len(oldLines) == 0 && len(newLines) == 0 {
+ return nil
+ }
+
+ return &change{
+ Old: strings.Join(oldLines, "\n"),
+ New: strings.Join(newLines, "\n"),
+ Line: startLine,
+ Length: len(oldLines),
+ }
+}
diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.go
index 6fbd271b..68ba0e05 100644
--- a/app/server/model/plan/build_exec.go
+++ b/app/server/model/plan/build_exec.go
@@ -282,7 +282,7 @@ func (fileState *activeBuildStreamFileState) buildFile() {
activeBuild.CurrentFileTokens = currentNumTokens
}
- fileState.buildFileLineNums()
+ fileState.buildExpandReferences()
}
func (fileState *activeBuildStreamFileState) buildFileLineNums() {
diff --git a/app/server/model/plan/build_refs.go b/app/server/model/plan/build_refs.go
index c5cb3178..b41df97d 100644
--- a/app/server/model/plan/build_refs.go
+++ b/app/server/model/plan/build_refs.go
@@ -6,7 +6,6 @@ import (
"log"
"math/rand"
"plandex-server/db"
- "plandex-server/external/diff"
"plandex-server/hooks"
"plandex-server/model"
"plandex-server/model/prompts"
@@ -139,6 +138,9 @@ func (fileState *activeBuildStreamFileState) buildExpandReferences() {
refsChoice := resp.Choices[0]
refsXml := refsChoice.Message.Content
+ log.Println("buildExpandReferences - refsXml:")
+ log.Println(refsXml)
+
refsSplit := strings.Split(refsXml, "<references>")
if len(refsSplit) != 2 {
log.Printf("buildExpandReferences - error processing references xml\n")
@@ -224,14 +226,11 @@ func (fileState *activeBuildStreamFileState) buildExpandReferences() {
fileState.updated = updatedFile
- edits := diff.Strings(originalFile, updatedFile)
- replacements := []*shared.Replacement{}
- for _, edit := range edits {
- old := originalFile[edit.Start:edit.End]
- replacements = append(replacements, &shared.Replacement{
- Old: old,
- New: edit.New,
- })
+ replacements, err := db.GetDiffReplacements(originalFile, updatedFile)
+ if err != nil {
+ log.Printf("buildExpandReferences - error getting diff replacements: %v\n", err)
+ fileState.expandRefsRetryOrError(fmt.Errorf("error getting diff replacements: %v", err))
+ return
}
res := db.PlanFileResult{
@@ -243,7 +242,7 @@ func (fileState *activeBuildStreamFileState) buildExpandReferences() {
Content: "",
Path: filePath,
Replacements: replacements,
- CanVerify: true,
+ CanVerify: false, // not sure yet whether verification is needed with ref expansion
}
validationRes, err := syntax.Validate(activePlan.Ctx, filePath, updatedFile)
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index 599766eb..9147668e 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
+ "time"
"plandex-server/db"
"plandex-server/hooks"
@@ -75,11 +76,14 @@ func execTellPlan(
})
if apiErr != nil {
+ time.Sleep(100 * time.Millisecond)
+ active.StreamDoneCh <- apiErr
return
}
}
planId := plan.Id
+ log.Println("execTellPlan - Setting plan status to replying")
err := db.SetPlanStatus(planId, branch, shared.PlanStatusReplying, "")
if err != nil {
log.Printf("Error setting plan %s status to replying: %v\n", planId, err)
@@ -92,6 +96,7 @@ func execTellPlan(
log.Printf("execTellPlan: execTellPlan operation completed for plan ID %s on branch %s, iteration %d\n", plan.Id, branch, iteration)
return
}
+ log.Println("execTellPlan - Plan status set to replying")
state := &activeTellStreamState{
clients: clients,
@@ -106,10 +111,12 @@ func execTellPlan(
currentReplyNumRetries: numErrorRetry,
}
+ log.Println("execTellPlan - Loading tell plan")
err = state.loadTellPlan()
if err != nil {
return
}
+ log.Println("execTellPlan - Tell plan loaded")
if iteration == 0 && missingFileResponse == "" {
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
diff --git a/app/shared/ai_models.go b/app/shared/ai_models.go
index 03b67206..746331ca 100644
--- a/app/shared/ai_models.go
+++ b/app/shared/ai_models.go
@@ -159,18 +159,16 @@ var AvailableModelsByName = map[string]*AvailableModel{}
var OpenRouterClaude3Dot5SonnetGPT4oModelPack ModelPack
var OpenRouterClaude3Dot5SonnetModelPack ModelPack
var Gpt4oLatestModelPack ModelPack
-var Gpt4o8062024ModelPack ModelPack
var GoogleGeminiModelPack ModelPack
var BuiltInModelPacks = []*ModelPack{
- &Gpt4o8062024ModelPack,
&Gpt4oLatestModelPack,
&OpenRouterClaude3Dot5SonnetModelPack,
&OpenRouterClaude3Dot5SonnetGPT4oModelPack,
&GoogleGeminiModelPack,
}
-var DefaultModelPack *ModelPack = &Gpt4oLatestModelPack
+var DefaultModelPack *ModelPack = &OpenRouterClaude3Dot5SonnetGPT4oModelPack
func getPlannerModelConfig(name string) PlannerModelConfig {
return PlannerModelConfig{
@@ -332,7 +330,7 @@ func init() {
},
Builder: ModelRoleConfig{
Role: ModelRoleBuilder,
- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
},