Skip to content

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

various fixes - missing file, build whole file calculation, reserved output tokens, condensing of sys prompt, only include one instance of large file update instructions in sys prompt, streamlining of context step

Dane Schneiderdf287d524d0c
diff --git a/app/cli/cmd/models.go b/app/cli/cmd/models.go
index 3764901e..a94de8cb 100644
--- a/app/cli/cmd/models.go
+++ b/app/cli/cmd/models.go
@@ -446,7 +446,7 @@ func renderSettings(settings *shared.PlanSettings) {
config.BaseModelConfig.ModelName,
fmt.Sprintf("%.1f", config.Temperature),
fmt.Sprintf("%.1f", config.TopP),
- fmt.Sprintf("%d 🪙", config.ReservedOutputTokens),
+ fmt.Sprintf("%d 🪙", config.GetReservedOutputTokens()),
})
}
diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.go
index e2d8d41c..18a7be4f 100644
--- a/app/cli/stream_tui/update.go
+++ b/app/cli/stream_tui/update.go
@@ -275,6 +275,9 @@ func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate bo
return m.checkMissingFile(msg)
case shared.StreamMessageReply:
+ // log.Println("Stream message reply:")
+ // log.Println(spew.Sdump(msg))
+
// ignore empty reply messages
if msg.ReplyChunk == "" {
return m, nil
@@ -299,6 +302,8 @@ func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate bo
m.reply += msg.ReplyChunk
+ // log.Println(m.reply)
+
if !deferUIUpdate {
m.updateReplyDisplay()
}
diff --git a/app/plans/json-prompts-to-xml.md b/app/plans/json-prompts-to-xml.md
new file mode 100644
index 00000000..08a101fe
--- /dev/null
+++ b/app/plans/json-prompts-to-xml.md
@@ -0,0 +1,19 @@
+I want to update a number of LLM calls to use XML for output instead of JSON. Here are the calls I want to update:
+
+- commit message ('genPlanDescription' call)
+- exec status ('execStatusShouldContinue' call)
+- naming functions - 'GenPlanName', 'GenPipedDataName', and 'GenNoteName'
+
+Look at 'build_exec.go' for an example of how to extract XML from a response.
+
+For each of the LLM calls:
+
+- update the corresponding prompt - get rid of the json schema and instead update the prompts to output the same data using xml tags instead of a JSON function call. do not use XML attributes, just simple tags. if there are multiple results in the json schema for the function call, update the prompt to output multiple tags. keep the rest of the prompts exactly the same.
+
+- look at the corresponding prompts for the build (in prompt/build.go) and use similar language for outputting xml tags.
+
+- update the post LLM call handling to extract the appropriate data using xml tags instead of json.
+
+- apart from the updated prompts, do not change other parameters in the LLM calls (like model, temperature, etc.)
+
+- I don't want to have any nesting in the xml. the response should just contain multiple tags at the top level if multiple tags are needed. also, it must be clear in all cases that the output should be the content of the tag and not an attribute... brief examples must be included in every prompt as well.
\ No newline at end of file
diff --git a/app/server/db/settings_helpers.go b/app/server/db/settings_helpers.go
index 8165921c..a32db463 100644
--- a/app/server/db/settings_helpers.go
+++ b/app/server/db/settings_helpers.go
@@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
+ "log"
"os"
"path/filepath"
"time"
@@ -93,6 +94,7 @@ func GetOrgDefaultSettings(orgId string, fillDefaultModelPack bool) (*shared.Pla
if err != nil {
if err == sql.ErrNoRows {
+ log.Println("GetOrgDefaultSettings - no rows - returning default settings")
// if it doesn't exist, return default settings object
settings := &shared.PlanSettings{
UpdatedAt: time.Time{},
@@ -105,6 +107,11 @@ func GetOrgDefaultSettings(orgId string, fillDefaultModelPack bool) (*shared.Pla
return nil, fmt.Errorf("error getting default plan settings: %v", err)
}
+ // fill in default WholeFileBuilder if not set
+ if defaults.PlanSettings.ModelPack.WholeFileBuilder == nil {
+ defaults.PlanSettings.ModelPack.WholeFileBuilder = shared.DefaultModelPack.WholeFileBuilder
+ }
+
return &defaults.PlanSettings, nil
}
diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.go
index cf5c4d0d..b89748ae 100644
--- a/app/server/model/plan/build_structured_edits.go
+++ b/app/server/model/plan/build_structured_edits.go
@@ -90,13 +90,44 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {
log.Println(spew.Sdump(applyRes.NeedsVerifyReasons))
wholeFileConfig := fileState.settings.ModelPack.GetWholeFileBuilder()
- reservedOutputTokens := wholeFileConfig.ReservedOutputTokens
+
+ spew.Dump(wholeFileConfig)
+
+ reservedOutputTokens := wholeFileConfig.GetReservedOutputTokens()
isSmallFile := maxPotentialTokens < SmallFileThreshold
- isBelowWholeFileThreshold := maxPotentialTokens < int(float32(reservedOutputTokens)*0.9)
+ threshold := int(float32(reservedOutputTokens) * 0.9)
+ isBelowWholeFileThreshold := maxPotentialTokens < threshold
shouldBuildSmallFile := isSmallFile && numTries == SmallFileTriesBeforeWholeFile && isBelowWholeFileThreshold
shouldBuildAnyFile := numTries == BuildTriesBeforeWholeFile && isBelowWholeFileThreshold
shouldBuildWholeFile := shouldBuildSmallFile || shouldBuildAnyFile
+ // log all the above variables
+ log.Printf("buildStructuredEdits - variables for whole file decision:\n"+
+ "filePath: %s\n"+
+ "content tokens: %d\n"+
+ "current file tokens: %d\n"+
+ "maxPotentialTokens: %d\n"+
+ "reservedOutputTokens: %d\n"+
+ "threshold: %d\n"+
+ "isSmallFile: %t\n"+
+ "isBelowWholeFileThreshold: %t\n"+
+ "shouldBuildSmallFile: %t\n"+
+ "shouldBuildAnyFile: %t\n"+
+ "shouldBuildWholeFile: %t\n"+
+ "numTries: %d",
+ filePath,
+ activeBuild.FileContentTokens,
+ activeBuild.CurrentFileTokens,
+ maxPotentialTokens,
+ reservedOutputTokens,
+ threshold,
+ isSmallFile,
+ isBelowWholeFileThreshold,
+ shouldBuildSmallFile,
+ shouldBuildAnyFile,
+ shouldBuildWholeFile,
+ numTries)
+
log.Printf("buildStructuredEdits - %s - num tries %d - should build small file %t - should build any file %t - should build whole file %t\n", filePath, numTries, shouldBuildSmallFile, shouldBuildAnyFile, shouldBuildWholeFile)
if shouldBuildWholeFile {
@@ -123,6 +154,9 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {
// log.Println(diff)
// }
+ log.Printf("buildStructuredEdits - %s - desc:\n%s\n", filePath, desc)
+ log.Printf("buildStructuredEdits - %s - proposedContent:\n%s\n", filePath, proposedContent)
+
validateSysPrompt := prompts.GetValidateEditsPrompt(filePath, originalFile, desc, proposedContent, diff, applyRes.NeedsVerifyReasons, syntaxErrors)
validateFileMessages := []openai.ChatCompletionMessage{
@@ -147,7 +181,7 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {
Plan: fileState.plan,
WillSendModelRequestParams: &hooks.WillSendModelRequestParams{
InputTokens: inputTokens,
- OutputTokens: config.ReservedOutputTokens,
+ OutputTokens: config.GetReservedOutputTokens(),
ModelName: config.BaseModelConfig.ModelName,
},
})
diff --git a/app/server/model/plan/build_whole_file.go b/app/server/model/plan/build_whole_file.go
index def4ec2b..fc000119 100644
--- a/app/server/model/plan/build_whole_file.go
+++ b/app/server/model/plan/build_whole_file.go
@@ -58,7 +58,7 @@ func (fileState *activeBuildStreamFileState) buildWholeFileFallback(proposedCont
Plan: fileState.plan,
WillSendModelRequestParams: &hooks.WillSendModelRequestParams{
InputTokens: inputTokens,
- OutputTokens: config.ReservedOutputTokens,
+ OutputTokens: config.GetReservedOutputTokens(),
ModelName: config.BaseModelConfig.ModelName,
},
})
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index 9df6d98e..899bb623 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -32,9 +32,9 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
s := fmt.Sprintf("**%s** has been completed", state.currentSubtask.Title)
log.Println("Checking if message contains subtask completion")
- log.Println(s)
- log.Println("---")
- log.Println(message)
+ // log.Println(s)
+ // log.Println("---")
+ // log.Println(message)
if strings.Contains(message, s) {
log.Println("Subtask marked completed in message. Will continue")
diff --git a/app/server/model/plan/tell_context.go b/app/server/model/plan/tell_context.go
index fed900bd..cfb07d94 100644
--- a/app/server/model/plan/tell_context.go
+++ b/app/server/model/plan/tell_context.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
+ "regexp"
"strings"
"github.com/plandex/plandex/shared"
@@ -11,6 +12,8 @@ import (
)
func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees, isImplementationStage, smartContextEnabled, execEnabled bool) (string, int, error) {
+ log.Println("Tell plan - formatModelContext")
+
var contextMessages []string = []string{
"### LATEST PLAN CONTEXT ###",
}
@@ -19,12 +22,14 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
uses := map[string]bool{}
if isImplementationStage && smartContextEnabled && state.currentSubtask != nil {
+ log.Println("Tell plan - formatModelContext - implementation stage - smart context enabled for current subtask")
for _, path := range state.currentSubtask.UsesFiles {
uses[path] = true
}
-
}
+ log.Printf("Tell plan - formatModelContext - implementation stage - smart context enabled for current subtask - uses: %v\n", uses)
+
for _, part := range state.modelContext {
if isImplementationStage && smartContextEnabled && state.currentSubtask != nil && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {
continue
@@ -86,6 +91,7 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
contextMessages = append(contextMessages, message)
}
+ log.Printf("Tell plan - formatModelContext - added context - %s\n", part.Name)
}
// Add any current files in plan that weren't added to the context
@@ -101,6 +107,8 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
}
contextMessages = append(contextMessages, fmt.Sprintf("\n\n- %s:\n\n```\n%s\n```", filePath, body))
+
+ log.Printf("Tell plan - formatModelContext - added current plan file - %s\n", filePath)
}
}
@@ -110,6 +118,9 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
contextMessages = append(contextMessages, fmt.Sprintf("- %s", path))
}
contextMessages = append(contextMessages, "These files have been *removed* and are no longer in the plan. If you want to re-add them to the plan, you must explicitly create them again.")
+
+ log.Println("Tell plan - formatModelContext - added removed files")
+ log.Println(contextMessages)
}
if execEnabled &&
@@ -130,7 +141,11 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
return strings.Join(contextMessages, "\n### END OF CONTEXT ###\n"), numTokens, nil
}
+var pathRegex = regexp.MustCompile("`(.+?)`")
+
func (state *activeTellStreamState) checkAutoLoadContext() []string {
+ req := state.req
+
activePlan := GetActivePlan(state.plan.Id, state.branch)
if activePlan == nil {
@@ -148,36 +163,23 @@ func (state *activeTellStreamState) checkAutoLoadContext() []string {
return nil
}
- // only load context on the first iteration of a non-continue prompt
- if state.iteration > 0 {
+ if !(state.isContextStage || state.isPlanningStage) {
return nil
}
- split := strings.Split(activePlan.CurrentReplyContent, "### Load Context")
+ // pick out all potential file paths within backticks
+ matches := pathRegex.FindAllStringSubmatch(activePlan.CurrentReplyContent, -1)
- if len(split) < 2 {
- return nil
- }
-
- req := state.req
-
- list := strings.Split(split[1], "\n")
files := []string{}
- for _, line := range list {
- trimmed := strings.TrimSpace(line)
+ for _, match := range matches {
+ trimmed := strings.TrimSpace(match[1])
if trimmed == "" {
continue
}
- if strings.HasPrefix(trimmed, "-") {
- trimmed = strings.TrimPrefix(trimmed, "-")
- trimmed = strings.ReplaceAll(trimmed, "`", "")
- trimmed = strings.TrimSpace(trimmed)
-
- if req.ProjectPaths[trimmed] && contextsByPath[trimmed] == nil {
- files = append(files, trimmed)
- }
+ if req.ProjectPaths[trimmed] && contextsByPath[trimmed] == nil {
+ files = append(files, trimmed)
}
}
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index ecccc8ef..a12156b9 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -198,6 +198,8 @@ func execTellPlan(
wrapperTokens = prompts.ImplementationPromptWrapperTokens
}
+ log.Printf("wrapperTokens: %d\n", wrapperTokens)
+
if iteration == 0 && missingFileResponse == "" {
numPromptTokens, err = shared.GetNumTokens(req.Prompt)
if err != nil {
@@ -214,10 +216,16 @@ func execTellPlan(
promptTokens = wrapperTokens + numPromptTokens + osDetailsTokens
} else if iteration > 0 && missingFileResponse == "" {
numPromptTokens = prompts.AutoContinuePromptTokens
+
+ log.Printf("numPromptTokens: %d\n", numPromptTokens)
+ log.Printf("osDetailsTokens: %d\n", osDetailsTokens)
+ log.Printf("wrapperTokens: %d\n", wrapperTokens)
+
promptTokens = wrapperTokens + numPromptTokens + osDetailsTokens
}
if req.ExecEnabled {
+ log.Printf("Apply script summary num tokens: %d\n", prompts.ApplyScriptSummaryNumTokens)
promptTokens += prompts.ApplyScriptSummaryNumTokens
}
@@ -272,7 +280,7 @@ func execTellPlan(
Plan: plan,
WillSendModelRequestParams: &hooks.WillSendModelRequestParams{
InputTokens: state.totalRequestTokens,
- OutputTokens: state.settings.ModelPack.Planner.ReservedOutputTokens,
+ OutputTokens: state.settings.ModelPack.Planner.GetReservedOutputTokens(),
ModelName: state.settings.ModelPack.Planner.BaseModelConfig.ModelName,
},
})
diff --git a/app/server/model/plan/tell_stream_main.go b/app/server/model/plan/tell_stream_main.go
index cfbf04e7..75fcf82c 100644
--- a/app/server/model/plan/tell_stream_main.go
+++ b/app/server/model/plan/tell_stream_main.go
@@ -100,6 +100,11 @@ mainLoop:
choice := response.Choices[0]
+ processChunkRes := state.processChunk(choice)
+ if processChunkRes.shouldReturn {
+ return
+ }
+
if choice.FinishReason != "" {
log.Println("Model stream finished")
log.Println("Finish reason: ", choice.FinishReason)
@@ -133,11 +138,6 @@ mainLoop:
streamFinished = true
continue
}
-
- processChunkRes := state.processChunk(choice)
- if processChunkRes.shouldReturn {
- return
- }
// let main loop continue
}
}
diff --git a/app/server/model/plan/tell_stream_processor.go b/app/server/model/plan/tell_stream_processor.go
index 42b892a7..223ac4c1 100644
--- a/app/server/model/plan/tell_stream_processor.go
+++ b/app/server/model/plan/tell_stream_processor.go
@@ -22,7 +22,7 @@ type processChunkResult struct {
func (state *activeTellStreamState) processChunk(choice openai.ChatCompletionStreamChoice) processChunkResult {
req := state.req
- missingFileResponse := state.missingFileResponse
+ // missingFileResponse := state.missingFileResponse
processor := state.chunkProcessor
replyParser := state.replyParser
plan := state.plan
@@ -35,33 +35,40 @@ func (state *activeTellStreamState) processChunk(choice openai.ChatCompletionStr
return processChunkResult{}
}
- processor.chunksReceived++
delta := choice.Delta
content := delta.Content
- // log.Printf("content: %s\n", content)
-
- // buffer if we're continuing after a missing file response to avoid sending redundant opening tags
- if missingFileResponse != "" {
- if processor.maybeRedundantOpeningTagContent != "" {
- if strings.Contains(content, "\n") {
- processor.maybeRedundantOpeningTagContent = ""
- } else {
- processor.maybeRedundantOpeningTagContent += content
- }
+ if content == "" {
+ return processChunkResult{}
+ }
- // skip processing this chunk
- return processChunkResult{}
- } else if processor.chunksReceived < 3 && strings.Contains(content, "<PlandexBlock") {
- // received <PlandexBlock in first 3 chunks after missing file response
- // means this is a redundant start of a new file block, so just ignore it
+ processor.chunksReceived++
- processor.maybeRedundantOpeningTagContent += content
+ // log.Printf("content: %s\n", content)
- // skip processing this chunk
- return processChunkResult{}
- }
- }
+ // Below needs reworking to correctly integrate with the rest of the processor
+ // Maybe isn't necessary anymore
+ // buffer if we're continuing after a missing file response to avoid sending redundant opening tags
+ // if missingFileResponse != "" {
+ // if processor.maybeRedundantOpeningTagContent != "" {
+ // if strings.Contains(content, "\n") {
+ // processor.maybeRedundantOpeningTagContent = ""
+ // } else {
+ // processor.maybeRedundantOpeningTagContent += content
+ // }
+
+ // // skip processing this chunk
+ // return processChunkResult{}
+ // } else if processor.chunksReceived < 3 && strings.Contains(content, "<PlandexBlock") {
+ // // received <PlandexBlock in first 3 chunks after missing file response
+ // // means this is a redundant start of a new file block, so just ignore it
+
+ // processor.maybeRedundantOpeningTagContent += content
+
+ // // skip processing this chunk
+ // return processChunkResult{}
+ // }
+ // }
// log.Printf("Adding chunk to parser: %s\n", content)
// log.Printf("fileOpen: %v\n", processor.fileOpen)
@@ -95,11 +102,13 @@ func (state *activeTellStreamState) processChunk(choice openai.ChatCompletionStr
// Handle file that is present in project paths but not in context
// Prompt user for what to do on the client side, stop the stream, and wait for user response before proceeding
+ bufferOrStreamRes := processor.bufferOrStream(content, &parserRes, state.isImplementationStage)
+
if currentFile != "" &&
!req.IsChatOnly &&
active.ContextsByPath[currentFile] == nil &&
req.ProjectPaths[currentFile] && !active.AllowOverwritePaths[currentFile] {
- return state.handleMissingFile(content, currentFile)
+ return state.handleMissingFile(bufferOrStreamRes.content, currentFile, bufferOrStreamRes.blockLang)
}
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
@@ -112,15 +121,13 @@ func (state *activeTellStreamState) processChunk(choice openai.ChatCompletionStr
// log.Println("maybeFilePath", parserRes.MaybeFilePath)
// log.Println("currentFilePath", parserRes.CurrentFilePath)
- res := processor.bufferOrStream(content, &parserRes, state.isImplementationStage)
-
// log.Println("res")
// spew.Dump(res)
- if res.shouldStream {
+ if bufferOrStreamRes.shouldStream {
active.Stream(shared.StreamMessage{
Type: shared.StreamMessageReply,
- ReplyChunk: res.content,
+ ReplyChunk: bufferOrStreamRes.content,
})
}
@@ -137,6 +144,7 @@ func (state *activeTellStreamState) processChunk(choice openai.ChatCompletionStr
type bufferOrStreamResult struct {
shouldStream bool
content string
+ blockLang string
}
func (processor *chunkProcessor) bufferOrStream(content string, parserRes *types.ReplyParserRes, isImplementationStage bool) bufferOrStreamResult {
@@ -149,6 +157,8 @@ func (processor *chunkProcessor) bufferOrStream(content string, parserRes *types
}
var shouldStream bool
+ var blockLang string
+
if processor.awaitingBlockOpeningTag || processor.awaitingBlockClosingTag || processor.awaitingBackticks || processor.awaitingOpClosingTag {
processor.contentBuffer.WriteString(content)
s := processor.contentBuffer.String()
@@ -193,7 +203,10 @@ func (processor *chunkProcessor) bufferOrStream(content string, parserRes *types
processor.contentBuffer.Reset()
shouldStream = true
} else if parserRes.CurrentFilePath != "" {
- matched, replaced := matchCodeBlockOpeningTag(s)
+ matched, replaced := replaceCodeBlockOpeningTag(s, func(lang string) string {
+ blockLang = lang
+ return "```" + lang
+ })
if matched {
shouldStream = true
@@ -288,7 +301,11 @@ func (processor *chunkProcessor) bufferOrStream(content string, parserRes *types
var matchedOpeningTag bool
if processor.fileOpen {
var replaced string
- matchedOpeningTag, replaced = matchCodeBlockOpeningTag(content)
+
+ matchedOpeningTag, replaced = replaceCodeBlockOpeningTag(content, func(lang string) string {
+ blockLang = lang
+ return "```" + lang
+ })
if matchedOpeningTag {
content = replaced
}
@@ -304,6 +321,7 @@ func (processor *chunkProcessor) bufferOrStream(content string, parserRes *types
return bufferOrStreamResult{
shouldStream: shouldStream,
content: content,
+ blockLang: blockLang,
}
}
@@ -362,6 +380,8 @@ func (state *activeTellStreamState) handleNewOperations(parserRes *types.ReplyPa
opContentTokens = op.NumTokens
}
+ log.Printf("buildState.queueBuilds - op.Description:\n%s\n", op.Description)
+
buildState.queueBuilds([]*types.ActiveBuild{{
ReplyId: replyId,
FileDescription: op.Description,
@@ -382,7 +402,7 @@ func (state *activeTellStreamState) handleNewOperations(parserRes *types.ReplyPa
}
-func (state *activeTellStreamState) handleMissingFile(content, currentFile string) processChunkResult {
+func (state *activeTellStreamState) handleMissingFile(content, currentFile, blockLang string) processChunkResult {
branch := state.branch
plan := state.plan
planId := plan.Id
@@ -415,23 +435,28 @@ func (state *activeTellStreamState) handleMissingFile(content, currentFile strin
return processChunkResult{}
}
- var previousReplyContent string
- var trimmedContent string
+ var trimmedReply string
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
ap.MissingFilePath = currentFile
- previousReplyContent = ap.CurrentReplyContent
- trimmedContent = replyParser.GetReplyForMissingFile()
- ap.CurrentReplyContent = trimmedContent
+ trimmedReply = replyParser.GetReplyForMissingFile()
+ ap.CurrentReplyContent = trimmedReply
})
- log.Println("Previous reply content:")
- log.Println(previousReplyContent)
+ // log.Println("Content:")
+ // log.Println(content)
+
+ // log.Println("Block lang:")
+ // log.Println(blockLang)
// log.Println("Trimmed content:")
- // log.Println(trimmedContent)
+ // log.Println(trimmedReply)
- chunkToStream := getCroppedChunk(previousReplyContent+content, trimmedContent, content)
+ // try to replace the code block opening tag in the chunk with an empty string
+ // this will remove the code block opening tag if it exists
+ splitBy := "```" + blockLang
+ split := strings.Split(content, splitBy)
+ chunkToStream := split[0] + splitBy + "\n"
// log.Printf("chunkToStream: %s\n", chunkToStream)
@@ -512,16 +537,16 @@ func getCroppedChunk(uncropped, cropped, chunk string) string {
return croppedChunk
}
-func matchCodeBlockOpeningTag(content string) (bool, string) {
+func replaceCodeBlockOpeningTag(content string, replaceWithFn func(lang string) string) (bool, string) {
// check for opening tag matching <PlandexBlock lang="...">
match := openingTagRegex.FindStringSubmatch(content)
if match != nil {
// Found complete opening tag with lang attribute
lang := match[1] // Extract the language from the first capture group
- return true, strings.Replace(content, match[0], "```"+lang, 1)
+ return true, strings.Replace(content, match[0], replaceWithFn(lang), 1)
} else if strings.Contains(content, "<PlandexBlock>") {
- return true, strings.Replace(content, "<PlandexBlock>", "```", 1)
+ return true, strings.Replace(content, "<PlandexBlock>", replaceWithFn(""), 1)
}
return false, ""
diff --git a/app/server/model/plan/tell_sys_prompt.go b/app/server/model/plan/tell_sys_prompt.go
index 5a3580f1..a4e39e6c 100644
--- a/app/server/model/plan/tell_sys_prompt.go
+++ b/app/server/model/plan/tell_sys_prompt.go
@@ -47,6 +47,17 @@ func (state *activeTellStreamState) getTellSysPrompt(isPlanningStage, isContextS
return false, "", 0
}
sysCreate = prompts.GetImplementationPrompt(state.currentSubtask.Title)
+ var err error
+ sysCreateTokens, err = shared.GetNumTokens(sysCreate)
+ if err != nil {
+ log.Printf("Error getting num tokens for implementation prompt: %v\n", err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error getting num tokens for implementation prompt",
+ }
+ return false, "", 0
+ }
}
if !isContextStage {
diff --git a/app/server/model/prompts/context_load.go b/app/server/model/prompts/context_load.go
index 1598e3d4..ddaa441f 100644
--- a/app/server/model/prompts/context_load.go
+++ b/app/server/model/prompts/context_load.go
@@ -9,13 +9,13 @@ In response to the user's latest prompt, do the following:
- Decide whether you've been given enough information to load necessary context and make a plan (if you've been given a task) or give a helpful response to the user (if you're responding in chat form). In general, do your best with whatever information you've been provided. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information. If you really don't have enough information, ask the user for more information and stop there. 'Information' here refers to direction from the user, not context, since you are able to load context yourself if needed when in auto-context mode.
- - Reply with a high level overview of how you will approach implementing the task (if you've been given a task) or responding to the user (if you're responding in chat form). Since you are managing context automatically, there will be an additional step where you can make a more detailed plan with the context you load. Still, try to consider *everything* the task will require and all the areas of the project it will need to touch. Be thorough and exhaustive in your plan, and don't leave out any steps. For example, if you're being asked to implement an API handler, don't forget that you will need to add the necessary routes to the router as well. Think carefully through details like these and strive not to leave out anything. Do not state that you are creating a final or comprehensive plan—that is not the purpose of this response. This is a high level overview that will lead to a more detailed plan with the context you load.
-
- - State something to the effect of: "I'll examine the codebase to determine which files I need."
-
- - Using the directory layout and the map, explain how the project is organized, with particular focus on areas that may be relevant to the user's task, question, or message.
+ - Reply with a brief, high level overview of how you will approach implementing the task (if you've been given a task) or responding to the user (if you're responding in chat form). Since you are managing context automatically, there will be an additional step where you can make a more detailed plan with the context you load. Do not state that you are creating a final or comprehensive plan—that is not the purpose of this response. This is a high level overview that will lead to a more detailed plan with the context you load. Do not call this overview a 'plan'—the purpose is only to help you exmaine the codebase to determine what context to load. You will then make a plan in the next step.
- - Using the map and file tree in context, output a '### Relevant Symbols' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path and the name of all potentially relevant symbols.
+ - If you already have enough information from the directory layout, map, and current context to make a detailed plan or respond effectively to the user and so you won't need to load any additional context, then explicitly say "No context needs to be loaded." and continue on to the instructions below.
+
+ - In a section titled '### Context Categories', list one or more categories of context that are relevant to the user's task, question, or message. For example, if the user is asking you to implement an API endpoint, you might list 'API endpoints', 'database operations', 'frontend code', 'utilities', and so on. Make sure any and all relevant categories are included, but don't include more categories than necessary—if only a single category is relevant, then only list that one. Do not include file paths, symbols, or explanations—only the categories.
+
+ - Using the map and file tree in context, output a '### Relevant Symbols' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path (surrounded by backticks) and the names of all potentially relevant symbols. File paths *absolutely must* be surrounded by backticks like this: ` + "`" + "path/to/file.go" + "`" + `. Any symbols that are referred to in the user's prompt must be included. Organize the list by category using the categories from the '### Context Categories' section.
` + ContextLoadingRules + `
@@ -23,49 +23,9 @@ In response to the user's latest prompt, do the following:
` + ContextCompletionCriteria + `
-- At the end of your response, list *all* of the files that are relevant and helpful to the user's task, question, or message in this EXACT format. You ABSOLUTELY MUST ensure that *all* files listed in the plan steps are included in the 'Load Context' list:
-
- ` + LoadContextFormatPrompt + `
-
- - If instead you already have enough information from the directory layout, map, and current context to make a detailed plan or respond effectively to the user and so you won't need to load any additional context, then explicitly say "No context needs to be loaded." and continue on to the instructions below.
-
- - Every response MUST end with either the 'Load Context' list in the exact format described above or the exact phrase "No context needs to be loaded." and nothing else. This MUST be the final text in your response.
-
-Don't output multiple lists of the files to load in your response. There MUST only be one 'Load Context' list in your response and no other list of the files to load.
-
[END OF CONTEXT INSTRUCTIONS]
`
-const LoadContextFormatPrompt = `
-### Load Context
-- ` + "`src/main.rs`" + `
-- ` + "`lib/term.go`" + `
-
-You MUST use the exact same format as shown directly above. First the '### Load Context' header, then a blank line, then the list of files, with a '-' and a space before each file path. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "- `src/main.rs`." + ` Each file path in the list MUST be on its own line. Use this EXACT format.
-
-After the 'Load Context' list, you MUST ALWAYS immediately *stop there* so these files can be loaded before you continue.
-
-The 'Load Context' list MUST *ONLY* include files that are present in the directory layout or map and are not *already* in context. You MUST NOT include any files that are already in context or that do not exist in the directory layout or map. **Do NOT include files that need to be created**—only files that already exist.
-
-Again, *DO NOT* load files that are already in context. *DO NOT* load files that do not exist *right now* in the directory layout or map.
-
-If any code similar to what the user is asking for exists in the project, include at least one example so that you can use it as a reference for how to implement the user's request in a way that is consistent with the existing code. If a user asks you to implement an API endpoint, for example, and you see that there is an existing endpoint in the project that is similar, include it in the context so that you can use it as a reference. Similarly, if a task requires implementing a database migration, and you see that there is an existing migration, include it in the context so that you can use it as a reference. If you are asked to implement a frontend or UI feature, and you see that there are existing UI components, pages, styles, or other related code, include some of it so that you can use it as a reference and keep a consistent style, both in terms of the code and the user experience.
-
-If you'll be using any definitions from a file—calling a function or method, instantiating a class, accessing a variable, using a type, and so on—include that file in the context. Include the file even if it's not being modified. For example, if you are creating an object that uses a type defined in a 'types.ts' file, include the 'types.ts' file in the context even if you're not updating the 'types.ts' file. If you're calling a function from a 'utils.py' file, include the 'utils.py' file in the context even if you're not updating the 'utils.py' file. This will ensure you correctly call functions/methods, use types, use variables and constants, etc. so it is *critical* that you include all files necessary to make a good plan that is well-integrated with the existing code.
-
-Include any files that the user has mentioned directly or indirectly in the prompt. If a user has mentioned files by name, path, by describing them, by referring to definitions or other code they contain, or by referring to them in any other way, include those files.
-
-If you aren't sure whether a file will be helpful or not, but you think it might be, include it in the 'Load Context' list. It's better to load more context than you need than to miss an important or helpful file.
-
-If context is included your prompt, you ABSOLUTELY MUST consider the context that is *ALREADY INCLUDED* and not load additional unnecessary context. It's EXTREMELY IMPORTANT that you do *NOT* load unnecessary context that is already included in the prompt. It's also EXTREMELY IMPORTANT you only list files that will be *UPDATED* during the plan. YOU ABSOLUTELY MUST NEVER include files that will be *CREATED* during the plan.
-
-If you have previously loaded context with a 'Load Context' list in an earlier response during this conversation, focus only on loading any *ADDITIONAL* context that are now helpful or relevant based on the user's latest prompt.
-
-If you have previously loaded context with a 'Load Context' list in an earlier response during this conversation, you DO NOT need to output an '### Additional Context' section. Load any additional context that is now helpful or relevant based on the user's latest prompt and then STOP there *immediately*.
-
-Once you've loaded all necessary context, move on to the instructions below.
-`
-
var AutoContextPreambleNumTokens int
const ContextLoadingRules = `When assessing relevant context, you MUST follow these rules:
@@ -99,7 +59,7 @@ const ContextLoadingRules = `When assessing relevant context, you MUST follow th
Remember: It's better to load more context than you need than to miss an important file. If you're not sure whether a file will be helpful, include it.`
-const FileMapScanningRules = `When examining the codebase, you MUST:
+const FileMapScanningRules = `When considering relevant categories in the '### Context Categories' and relevant symbols in the '### Relevant Symbols' sections:
1. Look for naming patterns:
- Files with similar prefixes or suffixes
@@ -119,18 +79,11 @@ const FileMapScanningRules = `When examining the codebase, you MUST:
* Related type definitions
Example: For 'api/methods.go', look for 'types/api.go', 'api/methods_test.go'`
-const ContextCompletionCriteria = `Before finalizing your context loading, verify you have:
+const ContextCompletionCriteria = `When considering relevant categories in the '### Context Categories' and relevant symbols in the '### Relevant Symbols' sections, make sure to include:
1. ALL interface files for any implementations
2. ALL type definitions related to the task or prompt
3. ALL similar feature files for reference
4. ALL utility files that might be related to the task or prompt
5. ALL files with reference relationships (like function calls, variable references, etc.)
-
-You ABSOLUTELY MUST reason through these points in a section titled "### Additional Context". EVERY response MUST include this section *before* the "Load Context" list.
-
-When reasoning through these points in "### Additional Context", *list specific file paths* that fit the criteria and have not yet been included in the response so far. DO NOT output a line like "Need API interface file" or "Need settings files". You MUST also include the specific file paths that fit the criteria. For example, "Need API interface file:` + "`types/api.go`" + ` or "Need settings files:` + "`settings/config.go`" + `,` + "`settings/user.go`" + ` ".
-
-If necessary files for one of these points has already been listed in the response, do not list them again. This section is for adding any additional files that haven't been mentioned previously. If all necessary files have already been listed, and so no additional context is necessary, say so and move on.
-
-You MUST explicitly state if you're missing any of these categories and load additional context if needed.`
+`
diff --git a/app/server/model/prompts/implement.go b/app/server/model/prompts/implement.go
index 47d65175..80e9d309 100644
--- a/app/server/model/prompts/implement.go
+++ b/app/server/model/prompts/implement.go
@@ -77,7 +77,9 @@ Don't include unnecessary comments in code. Lean towards no comments as much as
When updating an existing file in context, use the *reference comment* "// ... existing code ..." (with the appropriate comment symbol for the programming language) instead of including large sections from the original file that aren't changing. Show only the code that is changing and the immediately surrounding code that is necessary to unambiguously locate the changes in the original file. 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 NEVER use the comment "// ... existing code ..." (or any equivalent) when creating a new file.
-` + UpdateFormatPrompt + `
+` + UpdateFormatPrompt + `
+
+` + UpdateFormatAdditionalExamples + `
` + FileOpsImplementationPrompt + `
@@ -130,7 +132,10 @@ If the latest state of the context makes the current subtask you are working on
}
const CurrentSubtaskPrompt = `
-You will implement the *current subtask ONLY* in this response. You MUST NOT implement any other subtasks in this response. When the current subtask is complete, you MUST NOT move on to the next subtask. Instead, you must mark the current subtask as done and then end your response.
+You will implement the *current subtask ONLY* in this response. You MUST NOT implement any other subtasks in this response. When the current subtask is complete, you MUST NOT move on to the next subtask. Instead, you must mark the current subtask as done, output <PlandexSubtaskDone/>, and then end your response.
+
+Before marking the subtask as done, you MUST complete *every* step of the subtask. Do NOT skip any steps or mark the subtask as done before completing all the steps.
+
`
const MarkSubtaskDonePrompt = `
@@ -146,4 +151,12 @@ Example:
<PlandexSubtaskDone/>
It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. You MUST ALWAYS mark subtasks done with *exactly* this format. Use the *exact* name of the subtask (bolded) *exactly* as it is written in the subtask list and the CURRENT SUBTASK section and then "has been completed." in the response. Then you MUST ABSOLUTELY ALWAYS output <PlandexSubtaskDone/> and immediately end the response.
+
+Before marking the subtask as done, you MUST complete *every* step of the subtask. Do NOT skip any steps or mark the subtask as done before completing all the steps.
+
+You ABSOLUTELY MUST NOT mark the subtask as done by outputting text in the format "**[subtask name]** has been completed" and outputting <PlandexSubtaskDone/> until *every single step* of the subtask has been implemented with code blocks. DO NOT output this text or output <PlandexSubtaskDone/> after the first code block in the response *unless* that is the final step of the subtask. Otherwise, you must *continue* working on the remaining steps of the subtask with additional code blocks.
+
+If you are not able to finish *ALL* steps of the subtask in this response, you still MUST NOT mark the subtask as done by outputting text in the format "**[subtask name]** has been completed" and outputting <PlandexSubtaskDone/>. Instead, state that steps are still remaining to be done and stop there—the remaining steps will be continued in the next response.
`
+
+// Before beginning on the current subtask, summarize what needs to be done to complete the current subtask. Condense if possible, but do not leave out any necessary steps. Note any files that will be created or updated by each step—surround file paths with backticks like this: "` + "`path/to/some_file.txt`" + `". You MUST include this summary at the beginning of your response.
diff --git a/app/server/model/prompts/init.go b/app/server/model/prompts/init.go
index a6624872..fa86e6f3 100644
--- a/app/server/model/prompts/init.go
+++ b/app/server/model/prompts/init.go
@@ -39,6 +39,10 @@ func init() {
panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))
}
+ // log.Printf("ImplementationPromptWrapperTokens: %d\n", ImplementationPromptWrapperTokens)
+
+ // log.Println("implementationPromptWrapperFormatStr:\n", implementationPromptWrapperFormatStr)
+
AutoContinuePromptTokens, err = shared.GetNumTokens(AutoContinuePrompt)
if err != nil {
diff --git a/app/server/model/prompts/planning.go b/app/server/model/prompts/planning.go
index f9c5edf5..c2001abe 100644
--- a/app/server/model/prompts/planning.go
+++ b/app/server/model/prompts/planning.go
@@ -45,7 +45,7 @@ func GetPlanningPrompt(params createPromptParams) string {
}
prompt += `
- 2. Divide the user's task into one or more component subtasks and list them in a numbered list in a '### Tasks' section. Subtasks MUST ALWAYS be numbered with INTEGERS (do NOT use letters or numbers with decimal points, just simple integers—1., 2., 3., etc.) Start from 1. Subtask numbers MUST be followed by a period and a space, then the subtask name, then any additional information about the subtask in bullet points. Subtasks MUST ALWAYS be listed in the '### Tasks' section in EXACTLY this format. Example:
+ 2. Divide the user's task into one or more component subtasks and list them in a numbered list in a '### Tasks' section. Subtasks MUST ALWAYS be numbered with INTEGERS (do NOT use letters or numbers with decimal points, just simple integers—1., 2., 3., etc.) Start from 1. Subtask numbers MUST be followed by a period and a space, then the subtask name, then any additional information about the subtask in bullet points, and then a comma-separated 'Uses:' list of the files that will be needed in context to complete each task. Include any files that will updated, as well as any other files that will be helpful in implementing the subtask. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "`src/main.rs`." + ` Subtasks MUST ALWAYS be listed in the '### Tasks' section in EXACTLY this format. Example:
---
### Tasks
@@ -53,15 +53,20 @@ func GetPlanningPrompt(params createPromptParams) string {
1. Create a new file called 'game_logic.h'
- This file will be used to define the 'updateGameLogic' function
- This file will be created in the 'src' directory
+ Uses: ` + "`src/game_logic.h`" + `
2. Add the necessary code to the 'game_logic.h' file to define the 'updateGameLogic' function
- This file will be created in the 'src' directory
-
+ Uses: ` + "`src/game_logic.h`" + `
+
3. Create a new file called 'game_logic.c'
+ Uses: ` + "`src/game_logic.c`" + `
4. Add the necessary code to the 'game_logic.c' file to implement the 'updateGameLogic' function
+ Uses: ` + "`src/game_logic.c`" + `
5. Update the 'main.c' file to call the 'updateGameLogic' function
+ Uses: ` + "`src/main.c`" + `
<EndPlandexTasks/>
---
@@ -96,11 +101,11 @@ func GetPlanningPrompt(params createPromptParams) string {
if params.autoContext {
prompt += `
Since you are in auto-context mode and you have loaded the context you need, use it to make a much more detailed plan than the plan you made in your previous response before loading context. Be thorough in your planning.
-
- ` + UsesPrompt + `
- `
+ `
}
+ prompt += UsesPrompt
+
prompt += `
## Responding to user questions
@@ -119,7 +124,7 @@ If a plan is in progress and the user asks you a question, don't respond by cont
}
const UsesPrompt = `
-- Since you are in 'auto-context mode', below the description of each subtask, you MUST include a comma-separated 'Uses:' list of the files that will be needed in context to complete each task. Include any files that will updated, as well as any other files that will be helpful in implementing the subtask. ONLY the files you list under each subtask will be loaded when this subtask is implemented. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "`src/main.rs`." + `
+- You MUST include a comma-separated 'Uses:' list of the files that will be needed in context to complete each task. Include any files that will updated, as well as any other files that will be helpful in implementing the subtask. ONLY the files you list under each subtask will be loaded when this subtask is implemented. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "`src/main.rs`." + `
Example:
@@ -144,6 +149,8 @@ You MUST USE 'Uses:' *exactly* for this purpose. DO NOT use 'Files:' or 'Files n
ALWAYS place 'Uses:' at the *end* of each subtask description.
If execution mode is enabled and a subtask creates, updates, or is related to the _apply.sh script, you MUST include ` + "`_apply.sh`" + `in the 'Uses:' list for that subtask.
+
+'Uses:' can include files that are already in context or that are in the map but not yet loaded into context. Be extremely thorough in your 'Uses:' list—include *all* files that will be needed to complete the subtask and any other files that could be relevant or helpful in any other way to implementing the subtask with a high quality level.
`
var UsesPromptNumTokens int
diff --git a/app/server/model/prompts/summary.go b/app/server/model/prompts/summary.go
index 5d4d32df..4abe4e09 100644
--- a/app/server/model/prompts/summary.go
+++ b/app/server/model/prompts/summary.go
@@ -4,33 +4,8 @@ import (
"fmt"
"github.com/plandex/plandex/shared"
- "github.com/sashabaranov/go-openai"
- "github.com/sashabaranov/go-openai/jsonschema"
)
-const SysShortSummary = "You are an AI summarizer that summarizes text, including programs, documentation, websites, and more. Most text will be related to software development. You produce a brief summary of the text. A few sentences at most."
-
-var ShortSummaryFn = openai.FunctionDefinition{
- Name: "summarize",
- Parameters: &jsonschema.Definition{
- Type: jsonschema.Object,
- Properties: map[string]jsonschema.Definition{
- "summary": {
- Type: jsonschema.String,
- },
- },
- Required: []string{"summary"},
- },
-}
-
-func GetShortSummaryPrompt(text string) string {
- return `Please summarize the text below using the 'summarize' function. Call 'summarize' with valid JSON that includes the 'summary' key. You must ALWAYS call the 'summarize' function in your reponse. Don't call any other function.
-
- Text:
-
- ` + text
-}
-
const PlanSummary = `
You are an AI summarizer that summarizes the conversation so far. The conversation so far is a plan to complete one or more programming tasks for a user. This conversation may begin with an existing summary of the plan.
diff --git a/app/server/model/prompts/update_format.go b/app/server/model/prompts/update_format.go
index c83925cd..31399cab 100644
--- a/app/server/model/prompts/update_format.go
+++ b/app/server/model/prompts/update_format.go
@@ -65,7 +65,7 @@ class FooBar {
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. Remember, this *ONLY* applies to files that don't use comments. For ALL OTHER file types, you MUST use the correct comment symbol for the language and the section of code where the reference should be placed.
+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. Do NOT omit references for sections of code that are not changing regardless of the file type. Remember, this *ONLY* applies to files that don't use comments. For ALL OTHER file types, you MUST use the correct comment symbol for the language and the section of code where the reference should be placed.
For example, in a JSON file:
@@ -97,71 +97,38 @@ 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",
+ "name": "vscode-plandex",
"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:
+ "id": "plandex",
+ }],
+ "commands": [
+ {
+ "command": "plandex.tellPlandex",
+ }
+ ],
+ "keybindings": [{
+ "command": "plandex.showFilePicker",
+ }]
+ },
+ "scripts": {
+ "compile": "webpack",
+ },
+}
+---
+
+And you are adding a new key to the 'contributes' object, you MUST NOT output a code block like:
---
{
"contributes": {
- "languages": [
- {
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- "extensions": [".pd"],
- "configuration": "./language-configuration.json"
- }
- ],
+ "languages": [{
+ "id": "plandex",
+ }],
"grammars": [
{
"language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
}
]
}
@@ -169,9 +136,9 @@ And you are adding a new key to the 'contributes' object, you MUST NOT output a
---
-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.
+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:
+You also MUST NOT output a code block like:
---
@@ -179,23 +146,12 @@ You also MUST NOT output a file block like:
// ... existing code ...
"contributes":{
- "languages": [
- {
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- "extensions": [".pd"],
- "configuration": "./language-configuration.json"
- }
- ],
+ "languages": [{
+ "id": "plandex",
+ }],
"grammars": [
{
"language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
}
]
}
@@ -205,7 +161,7 @@ You also MUST NOT output a file block like:
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:
+Here's the CORRECT way to output the code block for this change:
---
@@ -213,25 +169,14 @@ 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"
- }
- ],
+ "languages": [{
+ "id": "plandex",
+ }],
"grammars": [
{
"language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
}
- ],
+ ]
// ... existing code ...
},
@@ -240,7 +185,7 @@ Here's the CORRECT way to output the file block for this change:
}
---
-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 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 code 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.
@@ -405,13 +350,13 @@ func main() {
}
---
-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.
+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 code 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.
+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 code 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.
+Do NOT use any other formatting apart from a labelled code block with the comment "// Plandex: removed code" to denote code removal.
Example of code being removed and not replaced with new code:
@@ -557,7 +502,7 @@ When using an "... existing code ..." comment, you must ensure that the lines ar
}
---
-DO NOT output a file block like this:
+DO NOT output a code block like this:
---
{
@@ -583,7 +528,7 @@ Note that the lines around the "... existing code ..." comment exactly match the
*
-When outputting a file block for a change, unless the change begins at the *start* of the file, you ABSOLUTELY MUST include an "... existing code ..." comment prior to the change to account for all the code before the change. Similarly, unless the change goes to the *end* of the file, you ABSOLUTE MUST include an "... existing code ..." comment after the change to account for all the code after the change. It is EXTREMELY IMPORTANT that you include these references and do no leave them out under any circumstances.
+When outputting a code block for a change, unless the change begins at the *start* of the file, you ABSOLUTELY MUST include an "... existing code ..." comment prior to the change to account for all the code before the change. Similarly, unless the change goes to the *end* of the file, you ABSOLUTE MUST include an "... existing code ..." comment after the change to account for all the code after the change. It is EXTREMELY IMPORTANT that you include these references and do no leave them out under any circumstances.
For example, if the original file looks like this:
@@ -601,7 +546,7 @@ func fooBar() {
}
---
-DO NOT output a file block like this:
+DO NOT output a code block like this:
---
func main() {
@@ -656,7 +601,7 @@ function callSomething() {
}
---
-DO NOT output a file block like this:
+DO NOT output a code block like this:
---
// ... existing code ...
@@ -690,7 +635,7 @@ function newFunction() {
By including the 'processResponse' function signature from the original code as an *anchor*, the location of the new code can be *unambiguously* located in the original file. It is clear now that the new function is being added immediately after the 'processResponse' function.
-It's EXTREMELY IMPORTANT that every file block that is *updating* an existing file includes at least one anchor that maps the lines from the original file to the lines in the file block so that the changes can be unambiguously located in the original file, and applied correctly.
+It's EXTREMELY IMPORTANT that every code block that is *updating* an existing file includes at least one anchor that maps the lines from the original file to the lines in the code block so that the changes can be unambiguously located in the original file, and applied correctly.
Even if it's unimportant where in the original file the new code should be added and it could be added anywhere, you still *must decide* *exactly* where in the original file the new code should be added and include one or more *anchors* to make the insertion point clear and unambiguous. Do NOT leave out anchors for a file update under any circumstances.
@@ -730,7 +675,7 @@ func last() {
---
-DO NOT output a file block like this to demonstrate that new code will be inserted somewhere between the 'fooBar' and 'last' functions:
+DO NOT output a code block like this to demonstrate that new code will be inserted somewhere between the 'fooBar' and 'last' functions:
---
// ... existing code ...
@@ -799,7 +744,7 @@ Either way, you MUST NOT leave out the "... existing code ..." comments for ANY
When including code from the original file to that is not changing and is intended to be used as an *anchor* to locate the insertion point of the new code, you ABSOLUTELY MUST NOT EVER change the order of the code in the original file. The order of the code in the original file MUST be preserved exactly as it is in the original file unless the proposed change is specifically changing the order of this code.
-If you are making multiple changes to the same file in a single file block, you MUST adhere to the order of the original file as closely as possible.
+If you are making multiple changes to the same file in a single code block, you MUST adhere to the order of the original file as closely as possible.
If the original file is:
@@ -825,7 +770,7 @@ func yup() {
}
---
-DO NOT output a file block like this to demonstrate that new code will be inserted between the 'fooBar' and 'baz' functions:
+DO NOT output a code block like this to demonstrate that new code will be inserted between the 'fooBar' and 'baz' functions:
---
// ... existing code ...
@@ -866,6 +811,10 @@ Now the order of the 'baz' and 'qux' functions is preserved exactly as it is in
*
+When writing an "... existing code ..." comment, you MUST use the correct comment symbol for the programming language. For example, if you are writing a plan in Python, Ruby, or Bash, you MUST use '# ... existing code ...' instead of '// ... existing code ...'. If you're writing HTML, you MUST use '<!-- ... existing code ... -->'. If you're writing jsx, tsx, svelte, or another language where the correct comment symbol(s) depend on where in the code you are, use the appropriate comment symbol(s) for where that comment is placed in the file. If you're in a javascript block of a jsx file, use '// ... existing code ...'. If you're in a markup block of a jsx file, use '{/* ... existing code ... */}'.
+`
+
+const UpdateFormatAdditionalExamples = `
Here are some important examples of INCORRECT vs CORRECT file updates:
Example 1 - Adding a new route:
@@ -979,25 +928,22 @@ This is wrong because it dropped existing configuration sections.
Key principles demonstrated in these examples:
1. Always show the surrounding context that will be preserved
2. Make insertion points unambiguous by showing adjacent code
-3. Never remove existing functionality
+3. Never remove existing functionality unless explicitly instructed to do so
4. Use "... existing code ..." comments properly to indicate preserved sections
5. Show enough context to understand the code structure
-
-*
-
-When writing an "... existing code ..." comment, you MUST use the correct comment symbol for the programming language. For example, if you are writing a plan in Python, Ruby, or Bash, you MUST use '# ... existing code ...' instead of '// ... existing code ...'. If you're writing HTML, you MUST use '<!-- ... existing code ... -->'. If you're writing jsx, tsx, svelte, or another language where the correct comment symbol(s) depend on where in the code you are, use the appropriate comment symbol(s) for where that comment is placed in the file. If you're in a javascript block of a jsx file, use '// ... existing code ...'. If you're in a markup block of a jsx file, use '{/* ... existing code ... */}'.
-
-Again, if you are writing a plan in a language that does not use '//' for comments, you absolutely must always use the appropriate comment symbol or symbols for that language instead of '//'. It is critically important that comments are ALWAYS written correctly for the language you are writing in.
`
const ChangeExplanationPrompt = `
-Prior to any file block that is *updating* an existing file in context, you MUST explain the change in the following format EXACTLY:
+### Action Explanation Format
+
+Prior to any code block that is *updating* an existing file in context, you MUST explain the change in the following format EXACTLY:
---
**Updating ` + "`[file path]`:**" + ` I'll [action explanation].
---
'action explanation' MUST ALWAYS take one of the following forms:
+
- 'add [new code description] between [specific code or structure in original file] and the immediately adjacent [specific *adjacent* code or structure in original file]'
- 'add [new code description] immediately after [specific code or structure in original file]'
- 'add [new code description] immediately before [specific code or structure in original file]'
@@ -1009,7 +955,9 @@ Prior to any file block that is *updating* an existing file in context, you MUST
- 'remove code between [specific code or structure in original file] and the immediately adjacent [specific *adjacent* code or structure in original file]'
- 'remove [specific code or structure in original file]'
-You ABSOLUTELY MUST use one of the above formats exactly as described, and EVERY file block that updates an existing file in context MUST *ALWAYS* be preceded with an explanation of the change in this *exact* format. Use the EXACT wording as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY!
+You ABSOLUTELY MUST use one of the above formats exactly as described, and EVERY code block that updates an existing file in context MUST *ALWAYS* be preceded with an explanation of the change in this *exact* format. Use the EXACT wording as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY!
+
+Do *NOT* UNDER ANY CIRCUMSTANCES use an explanation that does not match one of the above formats like "I'll update the code to...". You ABSOLUTELY MUST ALWAYS *exactly* match one of the above formats.
If you are inserting code between two existing code blocks, do NOT use the start or end of the file to describe the position of the change; instead, use the code or structure that is *immediately before* and *immediately after* the point where the new code will be inserted.
@@ -1027,9 +975,9 @@ Do NOT leave off any part of the explanation as described above. Do NOT output s
- **Updating ` + "`server/db/user.go`**" + `: I'll add a new ` + "`update`" + ` function immediately before the ` + "`getUser`" + ` method.
- **Updating ` + "`server/db/user.go`**" + `: I'll remove the ` + "`getUser`" + ` method.
-You ABSOLUTELY MUST use this template EXACTLY as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY! DO NOT OMIT ANY PART OF THE EXPLANATION AS DESCRIBED ABOVE. AND ABSOLUTELY DO NOT EVEN THINK ABOUT LEAVING OUT THIS MESSAGE! It is EXTREMELY IMPORTANT that you include this message in every file block that updates an existing file.
+You ABSOLUTELY MUST use this template EXACTLY as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY! DO NOT OMIT ANY PART OF THE EXPLANATION AS DESCRIBED ABOVE. AND ABSOLUTELY DO NOT EVEN THINK ABOUT LEAVING OUT THIS MESSAGE! It is EXTREMELY IMPORTANT that you include this message in every code block that updates an existing file.
-When creating a *new* file, do NOT include this explanation. Include *one* explanation in this format per file block that *updates* an existing file. Do NOT include multiple explanations in the same file block.
+When creating a *new* file, do NOT include this explanation. Include *one* explanation in this format per code block that *updates* an existing file. Do NOT include multiple explanations in the same code block.
When describing two specific code structures in the original file that new code will be inserted between, the two code structures MUST be *immediately adjacent* in the original file. DO NOT insert code between two code structures that aren't *immediately adjacent* in the original file. For example, if the original file is:
@@ -1066,7 +1014,7 @@ You can also output an explanation like this:
**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call immediately after the 'doSomethingOnceMore' method.
---
-The explanation MUST ALWAYS WITHOUT EXCPETION be immediately followed by the file block that updates the file in the EXACT format specified in section 2a of your instructions. DO NOT omit the file block label.
+The explanation MUST ALWAYS WITHOUT EXCPETION be immediately followed by the code block that updates the file in the EXACT format specified in section 2a of your instructions. DO NOT omit the code block label.
Example:
@@ -1088,13 +1036,13 @@ func Add(t *T) {
*
-ALL code structures that are mentioned in the explanation MUST be included as *anchors* in the file block that updates the file. If you are inserting new code between [structure 1] and [structure 2], then you MUST include both [structure 1] and [structure 2] as anchors in the file block that updates the file. You do not need to include the full structures—use "... existing code ..." reference comments if necessary to avoid outputting full structures, but you MUST include the anchors to make it clear and unambiguous where the new code is being inserted. The same applies if you are replacing code between [structure 1] and [structure 2] or removing code between [structure 1] and [structure 2].
+ALL code structures that are mentioned in the explanation MUST be included as *anchors* in the code block that updates the file. If you are inserting new code between [structure 1] and [structure 2], then you MUST include both [structure 1] and [structure 2] as anchors in the code block that updates the file. You do not need to include the full structures—use "... existing code ..." reference comments if necessary to avoid outputting full structures, but you MUST include the anchors to make it clear and unambiguous where the new code is being inserted. The same applies if you are replacing code between [structure 1] and [structure 2] or removing code between [structure 1] and [structure 2].
*
-If a file is being *updated* and the above explanation does not indicate that the file is being *overwritten* or that the change is being prepended to the *start* of the file, then the file block ABSOLUTELY ALWAYS MUST begin with an "... existing code ..." comment to account for all the code before the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.
+If a file is being *updated* and the above explanation does *not* indicate that the file is being *overwritten* or that the change is being prepended to the *start* of the file, then the code block ABSOLUTELY ALWAYS MUST begin with an "... existing code ..." comment to account for all the code before the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.
-If a file is being *updated* and the above explanation indicates that the file is being *overwritten* or that the change is being appended to the *end* of the file, then the file block ABSOLUTELY ALWAYS MUST end with an "... existing code ..." comment to account for all the code after the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.
+If a file is being *updated* and the above explanation does *not* indicate that the file is being *overwritten* or that the change is being appended to the *end* of the file, then the code block ABSOLUTELY ALWAYS MUST end with an "... existing code ..." comment to account for all the code after the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.
Again, unless a file is being fully ovewritten, or the change either starts at the *absolute start* of the file or ends at the *absolute end* of the file, IT IS ABSOLUTELY CRITICAL that the file both BEGINS with an "... existing code ..." comment and ENDS with an "... existing code ..." comment.
@@ -1102,7 +1050,7 @@ If a file must begin with an "... existing code ..." comment according to the ab
If a file must end with an "... existing code ..." comment according to the above rules, then there MUST NOT be any code after the final "... existing code ..." comment.
-Again, if the change *does not* end at the *absolute end* of the file, then the LAST LINE of the file block MUST be an "... existing code ..." comment. Ending the file block like this:
+Again, if the change *does not* end at the *absolute end* of the file, then the LAST LINE of the code block MUST be an "... existing code ..." comment. Ending the code block like this:
---
// ... existing code ...
diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.go
index ee01453c..0969f1e6 100644
--- a/app/server/model/prompts/user_prompt.go
+++ b/app/server/model/prompts/user_prompt.go
@@ -52,9 +52,35 @@ Always use an opening <PlandexBlock> tag to start a code block and a closing </P
The <PlandexBlock> tag MUST ONLY contain the code for the code block and NOTHING ELSE. Do NOT wrap the code block in triple backticks, CDATA tags, or any other text or formatting. Output ONLY the code and nothing else within the <PlandexBlock> tag.
-` + UpdateFormatPrompt + `
+You MUST follow the instructions you've been given on how to update code in code blocks:
-` + ChangeExplanationPrompt + `
+- Do 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. Use references comments for sections of the file that are not changing.
+
+- Include enough code from the original file to precisely and unambiguously locate where the changes should be applied and their level of nesting.
+
+- Match the indentation of the original file exactly.
+
+- Do NOT output multiple references with no changes in between them.
+
+- Do NOT add superfluous newlines around reference comments.
+
+- Use a removal comment to denote code that is being removed from a file. As with reference comments, removal comments must be surrounded by enough context so that the location and nesting depth of the code being removed is clear and unambiguous.
+
+- 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.
+
+- Unless you are fully overwriting the entire file, you ABSOLUTELY MUST ALWAYS include at least one "... existing code ..." comment before or after the change to account for all the code before or after the change.
+
+- Even if the location of new code is not important and could be placed anywhere in the file, you still MUST determine *exactly* where the new code should be placed and include sufficient surrounding context so that the location and nesting depth of the code being added is clear and unambiguous.
+
+- Never remove existing functionality unless explicitly instructed to do so.
+
+- Show enough surrounding context to understand the code structure.
+
+Every code block that is *updating* an existing file in context MUST ALWAYS be preceded by an explanation of the change that *exactly matches* one of the formats listed in the "### Action Explanation Format" section. Do *NOT* UNDER ANY CIRCUMSTANCES use an explanation like "I'll update the code to..." that does not match one of these formats.
+
+- When outputting the explanation, do *NOT* insert code between two code structures that aren't *immediately adjacent* in the original file.
+
+- When creating a *new* file, do NOT include this explanation. Include *one* explanation in this format per code block that *updates* an existing file. Do NOT include multiple explanations in the same code block.
Only list out subtasks once for the plan--after that, do not list or describe a subtask that can be implemented in code without including a code block that implements the subtask.
@@ -116,5 +142,7 @@ const SkippedPathsPrompt = "\n\nSome files have been skipped by the user and *mu
const CombineSubtasksPrompt = `
- Combine multiple steps into a single larger subtask where all of the steps are small enough to be completed in a single response (especially do this if multiple steps are closely related). Try to both size each subtask so that it can be completed in a single response, while also aiming to minimize the total number of subtasks. For subtasks involving multiple steps and/or multiple files, use bullet points to break them up into smaller sub-subtasks.
+- When using bullet points to break up a subtask into multiple steps, make a note of any files that will be created or updated by each step—surround file paths with backticks like this: "` + "`path/to/some_file.txt`" + `". All paths mentioned in the bullet points of the subtask must be included in the 'Uses: ' list for the subtask.
+
- Do NOT break up file operations of the same type (e.g. moving files, removing files, resetting pending changes) into multiple subtasks. Group them all into a *single* subtask.
`
diff --git a/app/server/syntax/structural_edits.go b/app/server/syntax/structural_edits.go
index 3e34ed63..6f276f81 100644
--- a/app/server/syntax/structural_edits.go
+++ b/app/server/syntax/structural_edits.go
@@ -116,7 +116,7 @@ func ApplyChanges(
}
if !beginsWithRef &&
- !strings.Contains(desc, "overwrite the entire file") &&
+ !strings.Contains(desc, "entire file") &&
!((strings.Contains(desc, "replace code") ||
strings.Contains(desc, "remove code")) &&
strings.Contains(desc, "start of the file")) {
@@ -135,7 +135,7 @@ func ApplyChanges(
}
if !endsWithRef &&
- !strings.Contains(desc, "overwrite the entire file") &&
+ !strings.Contains(desc, "entire file") &&
!(strings.Contains(desc, "replace code") ||
strings.Contains(desc, "remove code")) &&
!strings.Contains(desc, "end of the file") {
@@ -196,7 +196,7 @@ func ApplyChanges(
// return res
// }
- if !strings.Contains(desc, "overwrite the entire file") {
+ if !strings.Contains(desc, "entire file") {
originalLineMap := make(map[string]bool)
for _, line := range originalLines {
originalLineMap[strings.TrimSpace(line)] = true
diff --git a/app/server/syntax/validate.go b/app/server/syntax/validate.go
index 2e46062d..cfa2e4fa 100644
--- a/app/server/syntax/validate.go
+++ b/app/server/syntax/validate.go
@@ -44,6 +44,10 @@ func ValidateWithParsers(ctx context.Context, lang shared.TreeSitterLanguage, pa
tree, err := parser.ParseCtx(ctx, nil, []byte(file))
if err != nil || tree == nil {
+ if err != nil && err.Error() == "operation limit was hit" {
+ return &ValidationRes{Lang: lang, Parser: parser, TimedOut: true}, nil
+ }
+
return nil, fmt.Errorf("failed to parse the content: %v", err)
}
defer tree.Close()
diff --git a/app/server/types/reply.go b/app/server/types/reply.go
index 8c51f165..113775e4 100644
--- a/app/server/types/reply.go
+++ b/app/server/types/reply.go
@@ -1,7 +1,6 @@
package types
import (
- "log"
"os"
"strings"
@@ -166,18 +165,18 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {
if LineMaybeHasFilePath(prevFullLineTrimmed) {
gotPath = extractFilePath(prevFullLineTrimmed)
} else if prevFullLineTrimmed == "### Move Files" {
- log.Println("Found move block")
+ // log.Println("Found move block")
r.isInMoveBlock = true
} else if prevFullLineTrimmed == "### Remove Files" {
- log.Println("Found remove block")
+ // log.Println("Found remove block")
r.isInRemoveBlock = true
} else if prevFullLineTrimmed == "### Reset Changes" {
- log.Println("Found reset block")
+ // log.Println("Found reset block")
r.isInResetBlock = true
}
if gotPath != "" {
- log.Println("Detected possible file path:", gotPath) // Logging the possible file path
+ // log.Println("Detected possible file path:", gotPath) // Logging the possible file path
r.maybeFilePath = gotPath
}
} else if r.currentFilePath != "" {
@@ -196,7 +195,7 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {
// log.Printf("Added %d tokens to %s\n", tokens, r.currentFilePath) // Logging token addition
}
} else if r.isInMoveBlock || r.isInRemoveBlock || r.isInResetBlock {
- log.Println("In move, remove, or reset block")
+ // log.Println("In move, remove, or reset block")
if prevFullLineTrimmed == "<EndPlandexFileOps/>" {
// log.Println("Found closing tag--adding operations to operations and resetting pending operations...")
r.isInMoveBlock = false
diff --git a/app/shared/ai_models.go b/app/shared/ai_models.go
index 848eb5bd..479c830b 100644
--- a/app/shared/ai_models.go
+++ b/app/shared/ai_models.go
@@ -242,11 +242,10 @@ func init() {
Description: "Uses OpenAI's latest gpt-4o model for heavy lifting, and latest version of gpt-4o-mini for lighter tasks.",
Planner: PlannerRoleConfig{
ModelRoleConfig: ModelRoleConfig{
- Role: ModelRolePlanner,
- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRolePlanner,
+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
},
PlannerModelConfig: getPlannerModelConfig(openai.GPT4o),
},
@@ -257,11 +256,10 @@ func init() {
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
Builder: ModelRoleConfig{
- Role: ModelRoleBuilder,
- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRoleBuilder,
+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
},
Namer: ModelRoleConfig{
Role: ModelRoleName,
@@ -288,11 +286,10 @@ func init() {
Description: "Uses Anthropic's Claude 3.5 Sonnet model (via OpenRouter) for planning, summarization, diff-based edits, and auto-continue, OpenAI gpt-4o for whole-file edits, and gpt-4o-mini for lighter tasks.",
Planner: PlannerRoleConfig{
ModelRoleConfig: ModelRoleConfig{
- Role: ModelRolePlanner,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRolePlanner,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
},
PlannerModelConfig: getPlannerModelConfig("anthropic/claude-3.5-sonnet"),
},
@@ -303,18 +300,16 @@ func init() {
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
Builder: ModelRoleConfig{
- Role: ModelRoleBuilder,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRoleBuilder,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
},
WholeFileBuilder: &ModelRoleConfig{
- Role: ModelRoleWholeFileBuilder,
- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRoleWholeFileBuilder].Temperature,
- TopP: DefaultConfigByRole[ModelRoleWholeFileBuilder].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRoleWholeFileBuilder,
+ BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleWholeFileBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleWholeFileBuilder].TopP,
},
Namer: ModelRoleConfig{
Role: ModelRoleName,
@@ -341,11 +336,10 @@ func init() {
Description: "Uses Anthropic's Claude 3.5 Sonnet model (via OpenRouter) for planning, builds, and auto-continue, and summarization, and Claude 3 Haiku for lighter tasks.",
Planner: PlannerRoleConfig{
ModelRoleConfig: ModelRoleConfig{
- Role: ModelRolePlanner,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRolePlanner,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
},
PlannerModelConfig: getPlannerModelConfig("anthropic/claude-3.5-sonnet"),
},
@@ -356,11 +350,10 @@ func init() {
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
Builder: ModelRoleConfig{
- Role: ModelRoleBuilder,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRoleBuilder,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
},
Namer: ModelRoleConfig{
Role: ModelRoleName,
@@ -387,11 +380,10 @@ func init() {
Description: "Uses Google's Gemini Pro 1.5 model for heavy lifting and Gemini Flash 1.5 for lighter tasks.",
Planner: PlannerRoleConfig{
ModelRoleConfig: ModelRoleConfig{
- Role: ModelRolePlanner,
- BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
- TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRolePlanner,
+ BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRolePlanner].Temperature,
+ TopP: DefaultConfigByRole[ModelRolePlanner].TopP,
},
PlannerModelConfig: getPlannerModelConfig("google/gemini-pro-1.5"),
},
@@ -402,11 +394,10 @@ func init() {
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
Builder: ModelRoleConfig{
- Role: ModelRoleBuilder,
- BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,
- Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
- TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
- ReservedOutputTokens: AvailableModelsByName[openai.GPT4o].DefaultReservedOutputTokens,
+ Role: ModelRoleBuilder,
+ BaseModelConfig: AvailableModelsByName["google/gemini-pro-1.5"].BaseModelConfig,
+ Temperature: DefaultConfigByRole[ModelRoleBuilder].Temperature,
+ TopP: DefaultConfigByRole[ModelRoleBuilder].TopP,
},
Namer: ModelRoleConfig{
Role: ModelRoleName,
diff --git a/app/shared/data_models.go b/app/shared/data_models.go
index 0b3416ef..813e7ace 100644
--- a/app/shared/data_models.go
+++ b/app/shared/data_models.go
@@ -301,6 +301,13 @@ type ModelRoleConfig struct {
ReservedOutputTokens int `json:"reservedOutputTokens"`
}
+func (m *ModelRoleConfig) GetReservedOutputTokens() int {
+ if m.ReservedOutputTokens > 0 {
+ return m.ReservedOutputTokens
+ }
+ return AvailableModelsByName[m.BaseModelConfig.ModelName].DefaultReservedOutputTokens
+}
+
func (m *ModelRoleConfig) Scan(src interface{}) error {
if src == nil {
return nil
diff --git a/app/shared/plan_model_settings.go b/app/shared/plan_model_settings.go
index 40f75649..36e1441e 100644
--- a/app/shared/plan_model_settings.go
+++ b/app/shared/plan_model_settings.go
@@ -83,20 +83,8 @@ func (ps PlanSettings) GetPlannerMaxConvoTokens() int {
}
}
-func (ps PlanSettings) GetPlannerReservedOutputTokens() int {
- if ps.ModelOverrides.ReservedOutputTokens == nil {
- if ps.ModelPack == nil {
- return DefaultModelPack.Planner.ReservedOutputTokens
- } else {
- return ps.ModelPack.Planner.ReservedOutputTokens
- }
- } else {
- return *ps.ModelOverrides.ReservedOutputTokens
- }
-}
-
func (ps PlanSettings) GetPlannerEffectiveMaxTokens() int {
- return ps.GetPlannerMaxTokens() - ps.GetPlannerReservedOutputTokens()
+ return ps.GetPlannerMaxTokens() - ps.ModelPack.Planner.GetReservedOutputTokens()
}
func (ps PlanSettings) GetRequiredEnvVars() map[string]bool {