Skip to content

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

main prompt reorganization, split up planning and implementation phase prompts, deterministic subtask management, working on one subtask at a time with necessary context only, context prompt updates, update for claude-3.5-haiku

Dane Schneider0c4d161ed8e6
diff --git a/app/server/db/data_models.go b/app/server/db/data_models.go
index abb0573b..e2caf031 100644
--- a/app/server/db/data_models.go
+++ b/app/server/db/data_models.go
@@ -537,3 +537,10 @@ func (res *PlanFileResult) ToApi() *shared.PlanFileResult {
UpdatedAt: res.UpdatedAt,
}
}
+
+type Subtask struct {
+ Title string `json:"title"`
+ Description string `json:"description"`
+ UsesFiles []string `json:"usesFiles"`
+ IsFinished bool `json:"isFinished"`
+}
diff --git a/app/server/db/subtask_helpers.go b/app/server/db/subtask_helpers.go
new file mode 100644
index 00000000..2424645a
--- /dev/null
+++ b/app/server/db/subtask_helpers.go
@@ -0,0 +1,50 @@
+package db
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+func GetPlanSubtasks(orgId, planId string) ([]*Subtask, error) {
+ planDir := getPlanDir(orgId, planId)
+ subtasksPath := filepath.Join(planDir, "subtasks.json")
+
+ bytes, err := os.ReadFile(subtasksPath)
+
+ if err != nil {
+ if os.IsNotExist(err) {
+ return nil, nil
+ }
+
+ return nil, fmt.Errorf("error reading subtasks: %v", err)
+ }
+
+ var subtasks []*Subtask
+ err = json.Unmarshal(bytes, &subtasks)
+
+ if err != nil {
+ return nil, fmt.Errorf("error unmarshalling subtasks: %v", err)
+ }
+
+ return subtasks, nil
+}
+
+func StorePlanSubtasks(orgId, planId string, subtasks []*Subtask) error {
+ planDir := getPlanDir(orgId, planId)
+
+ bytes, err := json.Marshal(subtasks)
+
+ if err != nil {
+ return fmt.Errorf("error marshalling subtasks: %v", err)
+ }
+
+ err = os.WriteFile(filepath.Join(planDir, "subtasks.json"), bytes, os.ModePerm)
+
+ if err != nil {
+ return fmt.Errorf("error writing subtasks: %v", err)
+ }
+
+ return nil
+}
diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.go
index 82b9a87e..487b8ad9 100644
--- a/app/server/model/plan/build_finish.go
+++ b/app/server/model/plan/build_finish.go
@@ -186,12 +186,7 @@ func (state *activeBuildStreamFileState) onFinishBuild() {
active := GetActivePlan(planId, branch)
if active != nil && (active.RepliesFinished || active.BuildOnly) {
- if state.tellState != nil {
- log.Println("Build is finished and replies are finished, calling verifyOrFinish")
- state.tellState.verifyOrFinish()
- } else {
- active.Finish()
- }
+ active.Finish()
}
}
diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.go
index 45155fb9..c43eba41 100644
--- a/app/server/model/plan/build_structured_edits.go
+++ b/app/server/model/plan/build_structured_edits.go
@@ -195,15 +195,18 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {
// remove code block formatting if it was mistakenly included in the proposed content
trimmedProposedContent := strings.TrimSpace(proposedContent)
splitProposedContent := strings.Split(trimmedProposedContent, "\n")
- firstLine := strings.TrimSpace(splitProposedContent[0])
- secondLine := strings.TrimSpace(splitProposedContent[1])
- lastLine := strings.TrimSpace(splitProposedContent[len(splitProposedContent)-1])
- if types.LineMaybeHasFilePath(firstLine) && strings.HasPrefix(secondLine, "```") {
- if lastLine == "```" {
+
+ if len(splitProposedContent) > 2 {
+ firstLine := strings.TrimSpace(splitProposedContent[0])
+ secondLine := strings.TrimSpace(splitProposedContent[1])
+ lastLine := strings.TrimSpace(splitProposedContent[len(splitProposedContent)-1])
+ if types.LineMaybeHasFilePath(firstLine) && strings.HasPrefix(secondLine, "```") {
+ if lastLine == "```" {
+ proposedContent = strings.Join(splitProposedContent[1:len(splitProposedContent)-1], "\n")
+ }
+ } else if strings.HasPrefix(firstLine, "```") && lastLine == "```" {
proposedContent = strings.Join(splitProposedContent[1:len(splitProposedContent)-1], "\n")
}
- } else if strings.HasPrefix(firstLine, "```") && lastLine == "```" {
- proposedContent = strings.Join(splitProposedContent[1:len(splitProposedContent)-1], "\n")
}
// log.Println("buildStructuredEdits - fixed proposed content:")
diff --git a/app/server/model/plan/commit_msg.go b/app/server/model/plan/commit_msg.go
index 93904e26..f1a5003a 100644
--- a/app/server/model/plan/commit_msg.go
+++ b/app/server/model/plan/commit_msg.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log"
"plandex-server/db"
"plandex-server/hooks"
"plandex-server/model"
@@ -51,6 +52,8 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
return nil, errors.New(apiErr.Msg)
}
+ log.Println("Sending plan description model request")
+
descResp, err := model.CreateChatCompletionWithRetries(
client,
activePlan.Ctx,
@@ -89,6 +92,8 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
return nil, err
}
+ log.Println("Plan description model call complete")
+
var descStrRes string
var desc shared.ConvoMessageDescription
@@ -115,6 +120,8 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
}
}
+ log.Println("Sending DidSendModelRequest hook")
+
_, apiErr = hooks.ExecHook(hooks.DidSendModelRequest, hooks.HookParams{
Auth: auth,
Plan: plan,
@@ -133,6 +140,8 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
return nil, errors.New(apiErr.Msg)
}
+ log.Println("DidSendModelRequest hook complete")
+
if descStrRes == "" {
fmt.Println("no describePlan function call found in response")
return nil, fmt.Errorf("No describePlan function call found in response. This usually means the model failed to generate a valid response.")
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index b25cc411..9df6d98e 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -5,10 +5,10 @@ import (
"encoding/json"
"fmt"
"log"
- "plandex-server/db"
"plandex-server/hooks"
"plandex-server/model"
"plandex-server/model/prompts"
+ "plandex-server/types"
"strings"
"github.com/davecgh/go-spew/spew"
@@ -16,7 +16,7 @@ import (
"github.com/sashabaranov/go-openai"
)
-func (state *activeTellStreamState) execStatusShouldContinue(message string, latestSummaryCh chan *db.ConvoSummary, ctx context.Context) (bool, string, error) {
+func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx context.Context) (bool, bool, error) {
auth := state.auth
plan := state.plan
settings := state.settings
@@ -26,59 +26,31 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
envVar := config.BaseModelConfig.ApiKeyEnvVar
client := clients[envVar]
- log.Println("Checking if plan should continue based on exec status")
-
- // First try to determine if the plan should continue based on the last paragraph without calling the model
- paragraphs := strings.Split(message, "\n\n")
- lastParagraph := paragraphs[len(paragraphs)-1]
- lastParagraphLower := strings.ToLower(lastParagraph)
+ log.Println("Checking if plan should continue based on response text")
- // log.Printf("Last paragraph: %s\n", lastParagraphLower)
+ if state.currentSubtask != nil {
+ s := fmt.Sprintf("**%s** has been completed", state.currentSubtask.Title)
- if lastParagraphLower != "" {
- nextIdx := strings.Index(lastParagraph, "Next, ")
- if nextIdx >= 0 {
- log.Println("Plan can be continued based on last paragraph")
- return true, lastParagraph, nil
- }
- }
+ log.Println("Checking if message contains subtask completion")
+ log.Println(s)
+ log.Println("---")
+ log.Println(message)
- var prevAssistantMsg string
- if len(state.convo) > 1 {
- // iterate backwards from len(state.convo) - 2 to 0
- for i := len(state.convo) - 2; i >= 0; i-- {
- if state.convo[i].Role == "assistant" {
- prevAssistantMsg = state.convo[i].Message
- break
- }
+ if strings.Contains(message, s) {
+ log.Println("Subtask marked completed in message. Will continue")
+ return true, true, nil
}
}
- var latestSummary *db.ConvoSummary
-
- if latestSummaryCh != nil {
- log.Println("Waiting for latest summary")
- select {
- case <-ctx.Done():
- log.Println("Context cancelled while waiting for latest summary")
- return false, "", fmt.Errorf("context cancelled while waiting for latest summary")
- case latestSummary = <-latestSummaryCh:
- log.Println("Got latest summary")
- }
- }
-
- var summary string
- if latestSummary != nil {
- summary = latestSummary.Summary
- }
+ log.Println("Checking if plan should continue based on exec status")
- content := prompts.GetExecStatusShouldContinue(summary, prevAssistantMsg, state.userPrompt, message)
+ content := prompts.GetExecStatusShouldContinue(state.userPrompt, message)
contentTokens, err := shared.GetNumTokens(content)
if err != nil {
log.Printf("Error getting num tokens for content: %v\n", err)
- return false, "", fmt.Errorf("error getting num tokens for content: %v", err)
+ return false, false, fmt.Errorf("error getting num tokens for content: %v", err)
}
numTokens := prompts.ExtraTokensPerRequest + prompts.ExtraTokensPerMessage + contentTokens
@@ -93,7 +65,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
},
})
if apiErr != nil {
- return false, "", err
+ return false, false, fmt.Errorf("error executing hook: %v", apiErr)
}
messages := []openai.ChatCompletionMessage{
@@ -104,8 +76,6 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
}
log.Println("Calling model to check if plan should continue")
- log.Println("Has latest summary:", summary != "")
- log.Println("Has prev assistant msg:", prevAssistantMsg != "")
// log.Println("messages:")
// log.Println(spew.Sdump(messages))
@@ -144,19 +114,11 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
// return false, fmt.Errorf("error during plan exec status check model call: %v", err)
// Instead of erroring out, just don't continue the plan
- return false, "", nil
+ return false, false, nil
}
var strRes string
- var res struct {
- MessageFinishedSubtasks []string `json:"messageSubtasksFinished"`
- Comments []struct {
- Txt string `json:"txt"`
- IsTodoPlaceholder bool `json:"isTodoPlaceholder"`
- } `json:"comments"`
- Reasoning string `json:"reasoning"`
- ShouldContinue bool `json:"shouldContinue"`
- }
+ var res types.ExecStatusResponse
for _, choice := range resp.Choices {
if len(choice.Message.ToolCalls) == 1 &&
@@ -177,7 +139,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
outputTokens, err = shared.GetNumTokens(strRes)
if err != nil {
- return false, "", fmt.Errorf("error getting num tokens for res: %v", err)
+ return false, false, fmt.Errorf("error getting num tokens for res: %v", err)
}
}
@@ -196,7 +158,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
})
if apiErr != nil {
- return false, "", fmt.Errorf("error executing hook: %v", apiErr)
+ return false, false, fmt.Errorf("error executing hook: %v", apiErr)
}
if strRes == "" {
@@ -206,7 +168,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
// return false, fmt.Errorf("no shouldAutoContinue function call found in response")
// Instead of erroring out, just don't continue the plan
- return false, "", nil
+ return false, false, nil
}
err = json.Unmarshal([]byte(strRes), &res)
@@ -216,11 +178,11 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, lat
// return false, fmt.Errorf("error unmarshalling plan exec status response: %v", err)
// Instead of erroring out, just don't continue the plan
- return false, "", nil
+ return false, false, nil
}
log.Println("Plan exec status response:")
log.Println(spew.Sdump(res))
- return res.ShouldContinue, res.Reasoning, nil
+ return res.SubtaskFinished, res.ShouldContinue, nil
}
diff --git a/app/server/model/plan/context.go b/app/server/model/plan/tell_context.go
similarity index 85%
rename from app/server/model/plan/context.go
rename to app/server/model/plan/tell_context.go
index d1e5844d..410afc6c 100644
--- a/app/server/model/plan/context.go
+++ b/app/server/model/plan/tell_context.go
@@ -7,14 +7,25 @@ import (
"github.com/plandex/plandex/shared"
)
-func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees bool) (string, int, error) {
+func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees, isImplementationStage bool) (string, int, error) {
var contextMessages []string = []string{
"### LATEST PLAN CONTEXT ###",
}
var numTokens int
addedFilesSet := map[string]bool{}
+ uses := map[string]bool{}
+ if isImplementationStage {
+ for _, path := range state.currentSubtask.UsesFiles {
+ uses[path] = true
+ }
+ }
+
for _, part := range state.modelContext {
+ if isImplementationStage && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {
+ continue
+ }
+
var message string
var fmtStr string
var args []any
@@ -76,6 +87,11 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
// Add any current files in plan that weren't added to the context
for filePath, body := range state.currentPlanState.CurrentPlanFiles.Files {
if !addedFilesSet[filePath] {
+
+ if isImplementationStage && !uses[filePath] {
+ continue
+ }
+
contextMessages = append(contextMessages, fmt.Sprintf("\n\n- %s:\n\n```\n%s\n```", filePath, body))
}
}
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index 691d1a74..b7a44ffd 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -44,8 +44,6 @@ func Tell(clients map[string]*openai.Client, plan *db.Plan, branch string, auth
0,
"",
!req.IsChatOnly && req.BuildMode == shared.BuildModeAuto,
- "",
- "",
0,
)
@@ -62,8 +60,6 @@ func execTellPlan(
iteration int,
missingFileResponse shared.RespondMissingFileChoice,
shouldBuildPending bool,
- autoContinueNextTask string,
- verifyDiffs string,
numErrorRetry int,
) {
log.Printf("execTellPlan: Called for plan ID %s on branch %s, iteration %d\n", plan.Id, branch, iteration)
@@ -117,7 +113,6 @@ func execTellPlan(
branch: branch,
iteration: iteration,
missingFileResponse: missingFileResponse,
- verifyingDiffs: verifyDiffs,
currentReplyNumRetries: numErrorRetry,
}
@@ -163,6 +158,12 @@ func execTellPlan(
}
}
+ isPlanningStage := req.IsChatOnly || (!req.IsUserContinue && (iteration == 0 || (req.AutoContext && iteration == 1)))
+ isImplementationStage := !isPlanningStage
+ isContextStage := isPlanningStage && req.AutoContext && iteration == 0
+
+ log.Printf("isPlanningStage: %t, isImplementationStage: %t, isContextStage: %t\n", isPlanningStage, isImplementationStage, isContextStage)
+
// if auto context is enabled, we only include maps and trees on the first iteration, which is the context-gathering step, and the second iteration, which is the planning step
var (
includeMaps = true
@@ -173,7 +174,7 @@ func execTellPlan(
includeTrees = false
}
- modelContextText, modelContextTokens, err := state.formatModelContext(includeMaps, includeTrees)
+ modelContextText, modelContextTokens, err := state.formatModelContext(includeMaps, includeTrees, isImplementationStage)
if err != nil {
err = fmt.Errorf("error formatting model modelContext: %v", err)
log.Println(err)
@@ -187,43 +188,97 @@ func execTellPlan(
}
var sysCreate string
- var contextStage bool
- if req.AutoContext {
- if iteration == 0 {
- sysCreate = prompts.AutoContextPreamble + prompts.SysCreateAutoContext
- contextStage = true
+
+ var sysCreateTokens int
+
+ if isPlanningStage {
+ log.Println("isPlanningStage")
+ if req.AutoContext {
+ if iteration == 0 {
+ sysCreate = prompts.AutoContextPreamble
+ sysCreateTokens = prompts.AutoContextPreambleNumTokens
+ } else {
+ sysCreate = prompts.SysPlanningAutoContext
+ sysCreateTokens = prompts.SysPlanningAutoContextTokens
+ }
} else {
- sysCreate = prompts.SysCreateAutoContext
+ sysCreate = prompts.SysPlanningBasic
+ sysCreateTokens = prompts.SysPlanningBasicTokens
}
} else {
- sysCreate = prompts.SysCreateBasic
+ log.Println("isImplementationStage")
+ if state.currentSubtask == nil {
+ err = fmt.Errorf("no current subtask")
+ log.Println(err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "No current subtask",
+ }
+ return
+ }
+ sysCreate = prompts.GetImplementationPrompt(state.currentSubtask.Title)
}
- if !contextStage {
+ if !isContextStage {
if req.ExecEnabled {
sysCreate += prompts.ApplyScriptPrompt
+ sysCreateTokens += prompts.ApplyScriptPromptNumTokens
} else {
sysCreate += prompts.NoApplyScriptPrompt
+ sysCreateTokens += prompts.NoApplyScriptPromptNumTokens
}
}
// log.Println("sysCreate before context:\n", sysCreate)
- systemMessageText := sysCreate + modelContextText
- systemMessage := openai.ChatCompletionMessage{
- Role: openai.ChatMessageRoleSystem,
- Content: systemMessageText,
- }
+ sysCreate += modelContextText
if len(active.SkippedPaths) > 0 {
- systemMessageText += prompts.SkippedPathsPrompt
+ skippedPrompt := prompts.SkippedPathsPrompt
for skippedPath := range active.SkippedPaths {
- systemMessageText += fmt.Sprintf("- %s\n", skippedPath)
+ skippedPrompt += fmt.Sprintf("- %s\n", skippedPath)
+ }
+
+ numTokens, err := shared.GetNumTokens(skippedPrompt)
+ if err != nil {
+ log.Printf("Error getting num tokens for skipped paths: %v\n", err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error getting num tokens for skipped paths",
+ }
+ return
}
+
+ sysCreateTokens += numTokens
+ }
+
+ if len(state.subtasks) > 0 {
+ subtasksPrompt, subtaskTokens, err := state.formatSubtasks()
+
+ if err != nil {
+ err = fmt.Errorf("error formatting subtasks: %v", err)
+ log.Println(err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error formatting subtasks",
+ }
+ return
+ }
+
+ log.Println("subtasksPrompt:\n", subtasksPrompt)
+
+ sysCreate += subtasksPrompt
+ sysCreateTokens += subtaskTokens
}
state.messages = []openai.ChatCompletionMessage{
- systemMessage,
+ {
+ Role: openai.ChatMessageRoleSystem,
+ Content: sysCreate,
+ },
}
// Add a separate message for image contexts
@@ -274,6 +329,14 @@ func execTellPlan(
numPromptTokens int
promptTokens int
)
+
+ var wrapperTokens int
+ if isPlanningStage {
+ wrapperTokens = prompts.PlanningPromptWrapperTokens
+ } else {
+ wrapperTokens = prompts.ImplementationPromptWrapperTokens
+ }
+
if iteration == 0 && missingFileResponse == "" {
numPromptTokens, err = shared.GetNumTokens(req.Prompt)
if err != nil {
@@ -286,37 +349,17 @@ func execTellPlan(
}
return
}
- promptTokens = prompts.PromptWrapperTokens + numPromptTokens + osDetailsTokens
+
+ promptTokens = wrapperTokens + numPromptTokens + osDetailsTokens
} else if iteration > 0 && missingFileResponse == "" {
- if verifyDiffs != "" {
- numPromptTokens = prompts.VerifyDiffsPromptTokens
- } else {
- numPromptTokens = prompts.AutoContinuePromptTokens
- }
- promptTokens = prompts.PromptWrapperTokens + numPromptTokens + osDetailsTokens
+ numPromptTokens = prompts.AutoContinuePromptTokens
+ promptTokens = wrapperTokens + numPromptTokens + osDetailsTokens
}
if req.ExecEnabled {
promptTokens += prompts.ApplyScriptSummaryNumTokens
}
- var sysCreateTokens int
- if req.AutoContext {
- if iteration == 0 && !req.IsUserContinue {
- sysCreateTokens = prompts.AutoContextPreambleNumTokens
- } else {
- sysCreateTokens = prompts.SysCreateAutoContextNumTokens
- }
- } else {
- sysCreateTokens = prompts.SysCreateBasicNumTokens
- }
-
- if req.ExecEnabled {
- sysCreateTokens += prompts.ApplyScriptPromptNumTokens
- } else {
- sysCreateTokens += prompts.NoApplyScriptPromptNumTokens
- }
-
state.tokensBeforeConvo = sysCreateTokens + modelContextTokens + state.latestSummaryTokens + promptTokens
// print out breakdown of token usage
@@ -376,7 +419,7 @@ func execTellPlan(
state.messages = state.messages[:len(state.messages)-1]
promptMessage = &openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleUser,
- Content: prompts.GetWrappedPrompt(lastMessage.Content, req.OsDetails, applyScriptSummary),
+ Content: prompts.GetWrappedPrompt(lastMessage.Content, req.OsDetails, applyScriptSummary, isPlanningStage),
}
state.userPrompt = lastMessage.Content
@@ -388,7 +431,7 @@ func execTellPlan(
// otherwise we'll use the continue prompt
promptMessage = &openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleUser,
- Content: prompts.GetWrappedPrompt(prompts.UserContinuePrompt, req.OsDetails, applyScriptSummary),
+ Content: prompts.GetWrappedPrompt(prompts.UserContinuePrompt, req.OsDetails, applyScriptSummary, isPlanningStage),
}
}
@@ -408,59 +451,22 @@ func execTellPlan(
} else {
prompt = req.Prompt
}
- } else if verifyDiffs != "" {
- prompt = prompts.VerifyDiffsPrompt + verifyDiffs
-
- tokens, err := shared.GetNumTokens(verifyDiffs)
- if err != nil {
- log.Printf("Error getting num tokens for verify diffs: %v\n", err)
- active.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "Error getting num tokens for verify diffs",
- }
- return
- }
-
- state.totalRequestTokens += tokens
} else {
prompt = prompts.AutoContinuePrompt
-
- if autoContinueNextTask != "" {
- toAdd := `
- Here is the next task:
-
- ` + autoContinueNextTask + `
-
- Continue seamlessly with this task.
- `
-
- tokens, err := shared.GetNumTokens(toAdd)
- if err != nil {
- log.Printf("Error getting num tokens for auto continue next task: %v\n", err)
- active.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "Error getting num tokens for auto continue next task",
- }
- return
- }
-
- prompt += toAdd
- state.totalRequestTokens += tokens
- }
- }
-
- if iteration > 0 && verifyDiffs == "" && active.ShouldVerifyDiff() {
- prompt += prompts.WillVerifyPrompt
- state.totalRequestTokens += prompts.WillVerifyPromptTokens
}
state.userPrompt = prompt
+ var finalPrompt string
+ if isContextStage {
+ finalPrompt = prompt
+ } else {
+ finalPrompt = prompts.GetWrappedPrompt(prompt, req.OsDetails, applyScriptSummary, isPlanningStage)
+ }
+
promptMessage = &openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleUser,
- Content: prompts.GetWrappedPrompt(prompt, req.OsDetails, applyScriptSummary),
+ Content: finalPrompt,
}
}
@@ -519,7 +525,7 @@ func execTellPlan(
if missingFileResponse == shared.RespondMissingFileChoiceSkip {
res := state.replyParser.FinishAndRead()
skipPrompt := prompts.GetSkipMissingFilePrompt(res.CurrentFilePath)
- prompt := prompts.GetWrappedPrompt(skipPrompt, req.OsDetails, applyScriptSummary) + "\n\n" + skipPrompt // repetition of skip prompt to improve instruction following
+ prompt := prompts.GetWrappedPrompt(skipPrompt, req.OsDetails, applyScriptSummary, isPlanningStage) + "\n\n" + skipPrompt // repetition of skip prompt to improve instruction following
skipPromptTokens, err := shared.GetNumTokens(skipPrompt)
if err != nil {
@@ -541,7 +547,7 @@ func execTellPlan(
} else {
missingPrompt := prompts.GetMissingFileContinueGeneratingPrompt(res.CurrentFilePath)
- prompt := prompts.GetWrappedPrompt(missingPrompt, req.OsDetails, applyScriptSummary) + "\n\n" + missingPrompt // repetition of missing prompt to improve instruction following
+ prompt := prompts.GetWrappedPrompt(missingPrompt, req.OsDetails, applyScriptSummary, isPlanningStage) + "\n\n" + missingPrompt // repetition of missing prompt to improve instruction following
promptTokens, err = shared.GetNumTokens(prompt)
if err != nil {
diff --git a/app/server/model/plan/tell_load.go b/app/server/model/plan/tell_load.go
index 7581ca1e..b3b81c69 100644
--- a/app/server/model/plan/tell_load.go
+++ b/app/server/model/plan/tell_load.go
@@ -60,11 +60,12 @@ func (state *activeTellStreamState) loadTellPlan() error {
var modelContext []*db.Context
var convo []*db.ConvoMessage
var summaries []*db.ConvoSummary
+ var subtasks []*db.Subtask
var settings *shared.PlanSettings
var latestSummaryTokens int
var currentPlan *shared.CurrentPlanState
- // get name for plan and rename it's a draft
+ // get name for plan and rename if it's a draft
go func() {
res, err := db.GetPlanSettings(plan, true)
if err != nil {
@@ -255,6 +256,17 @@ func (state *activeTellStreamState) loadTellPlan() error {
errCh <- nil
}()
+ go func() {
+ res, err := db.GetPlanSubtasks(auth.OrgId, planId)
+ if err != nil {
+ log.Printf("Error getting plan subtasks: %v\n", err)
+ errCh <- fmt.Errorf("error getting plan subtasks: %v", err)
+ return
+ }
+ subtasks = res
+ errCh <- nil
+ }()
+
err = func() error {
var err error
defer func() {
@@ -278,7 +290,7 @@ func (state *activeTellStreamState) loadTellPlan() error {
}
}()
- for i := 0; i < 3; i++ {
+ for i := 0; i < 4; i++ {
err = <-errCh
if err != nil {
active.StreamDoneCh <- &shared.ApiError{
@@ -318,6 +330,14 @@ func (state *activeTellStreamState) loadTellPlan() error {
state.latestSummaryTokens = latestSummaryTokens
state.settings = settings
state.currentPlanState = currentPlan
+ state.subtasks = subtasks
+
+ for _, subtask := range state.subtasks {
+ if !subtask.IsFinished {
+ state.currentSubtask = subtask
+ break
+ }
+ }
return nil
}
diff --git a/app/server/model/plan/tell_state.go b/app/server/model/plan/tell_state.go
index 87ff470f..98dc64f7 100644
--- a/app/server/model/plan/tell_state.go
+++ b/app/server/model/plan/tell_state.go
@@ -34,5 +34,6 @@ type activeTellStreamState struct {
totalRequestTokens int
settings *shared.PlanSettings
currentReplyNumRetries int
- verifyingDiffs string
+ subtasks []*db.Subtask
+ currentSubtask *db.Subtask
}
diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.go
index 31f0b980..19f2494a 100644
--- a/app/server/model/plan/tell_stream.go
+++ b/app/server/model/plan/tell_stream.go
@@ -193,6 +193,7 @@ mainLoop:
continue mainLoop
}
+ time.Sleep(30 * time.Millisecond)
active.FlushStreamBuffer()
time.Sleep(100 * time.Millisecond)
@@ -207,13 +208,13 @@ mainLoop:
continue mainLoop
}
- latestSummaryCh := active.LatestSummaryCh
-
var generatedDescription *db.ConvoMessageDescription
var shouldContinue bool
- var nextTask string
+ var subtaskFinished bool
autoLoadContextFiles := state.checkAutoLoadContext()
+ hasNewSubtasks := state.checkNewSubtasks()
+ var allSubtasksFinished bool
var errCh = make(chan error, 2)
@@ -232,29 +233,31 @@ mainLoop:
generatedDescription.SummarizedToMessageId = summarizedToMessageId
generatedDescription.MadePlan = true
generatedDescription.Files = replyFiles
+
+ log.Println("Generated plan description.")
}
errCh <- nil
}()
- if req.IsChatOnly || len(autoLoadContextFiles) > 0 || active.DidVerifyDiff {
+ if req.IsChatOnly || len(autoLoadContextFiles) > 0 || hasNewSubtasks || !req.AutoContinue {
// if we're auto-loading context files, we always want to continue for at least another iteration with the loaded context (even if it's chat only)
- if len(autoLoadContextFiles) > 0 {
- log.Printf("Auto loading context files, so continuing")
+ if len(autoLoadContextFiles) > 0 && !hasNewSubtasks {
+ log.Printf("Auto loading context files, so continuing to planning phase")
shouldContinue = true
} else if req.IsChatOnly {
log.Printf("Chat only, won't continue")
shouldContinue = false
- } else if active.DidVerifyDiff {
- log.Printf("Did verify diff, won't continue")
- shouldContinue = false
+ } else if hasNewSubtasks {
+ log.Printf("Has new subtasks, can continue")
+ shouldContinue = req.AutoContinue
}
errCh <- nil
} else {
go func() {
log.Println("Getting exec status")
- shouldContinue, nextTask, err = state.execStatusShouldContinue(active.CurrentReplyContent, latestSummaryCh, active.Ctx)
+ subtaskFinished, shouldContinue, err = state.execStatusShouldContinue(active.CurrentReplyContent, active.Ctx)
if err != nil {
errCh <- fmt.Errorf("failed to get exec status: %v", err)
return
@@ -356,6 +359,32 @@ mainLoop:
return err
}
log.Println("Description stored")
+
+ if hasNewSubtasks || subtaskFinished {
+ if subtaskFinished {
+ log.Println("Subtask finished")
+ state.currentSubtask.IsFinished = true
+ }
+
+ err = db.StorePlanSubtasks(currentOrgId, planId, state.subtasks)
+ if err != nil {
+ log.Printf("Error storing plan subtasks: %v\n", err)
+ state.onError(fmt.Errorf("failed to store plan subtasks: %v", err), false, assistantMsg.Id, convoCommitMsg)
+ return err
+ }
+
+ state.currentSubtask = nil
+ allSubtasksFinished = true
+ for _, subtask := range state.subtasks {
+ if !subtask.IsFinished {
+ state.currentSubtask = subtask
+ allSubtasksFinished = false
+ break
+ }
+ }
+
+ }
+
// spew.Dump(description)
log.Println("Comitting reply message and description")
@@ -448,11 +477,16 @@ mainLoop:
log.Printf("shouldContinue: %v\n", shouldContinue)
log.Printf("iteration: %d\n", iteration)
log.Printf("MaxAutoContinueIterations: %d\n", MaxAutoContinueIterations)
+ log.Printf("hasNewSubtasks: %v\n", hasNewSubtasks)
+ log.Printf("len(state.subtasks): %d\n", len(state.subtasks))
+ log.Printf("allSubtasksFinished: %v\n", allSubtasksFinished)
- if len(autoLoadContextFiles) > 0 || (req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations) {
+ if (len(autoLoadContextFiles) > 0 && !hasNewSubtasks) ||
+ (req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations &&
+ !(len(state.subtasks) > 0 && allSubtasksFinished)) {
log.Println("Auto continue plan")
// continue plan
- execTellPlan(clients, plan, branch, auth, req, iteration+1, "", false, nextTask, "", 0)
+ execTellPlan(clients, plan, branch, auth, req, iteration+1, "", false, 0)
} else {
var buildFinished bool
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
@@ -468,32 +502,33 @@ mainLoop:
// ShouldVerifyDiff will always be false unless we re-enable tell-based verification
if buildFinished {
log.Println("Reply is finished and build is finished, calling verifyOrFinish")
- state.verifyOrFinish()
- } else {
- log.Println("Plan is still building")
+ active := GetActivePlan(planId, branch)
- if active.ShouldVerifyDiff() {
- // If we're going to verify the diffs when build finishes, then replies aren't finished yet so we'll just continue here
- log.Println("Build isn't finished yet—waiting on verify diff step")
+ if active == nil {
+ log.Printf("Active plan not found for planId: %s, branch: %s\n", planId, branch)
continue mainLoop
- } else {
- log.Println("Updating status to building")
- err := db.SetPlanStatus(planId, branch, shared.PlanStatusBuilding, "")
- if err != nil {
- log.Printf("Error setting plan status to building: %v\n", err)
- active.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "Error setting plan status to building",
- }
- continue mainLoop
- }
+ }
- log.Println("Sending RepliesFinished stream message")
- active.Stream(shared.StreamMessage{
- Type: shared.StreamMessageRepliesFinished,
- })
+ active.Finish()
+ } else {
+ log.Println("Plan is still building")
+ log.Println("Updating status to building")
+ err := db.SetPlanStatus(planId, branch, shared.PlanStatusBuilding, "")
+ if err != nil {
+ log.Printf("Error setting plan status to building: %v\n", err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error setting plan status to building",
+ }
+ continue mainLoop
}
+
+ log.Println("Sending RepliesFinished stream message")
+ active.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageRepliesFinished,
+ })
+
}
}
@@ -663,8 +698,6 @@ mainLoop:
iteration, // keep the same iteration
userChoice,
false,
- "",
- state.verifyingDiffs,
0,
)
return
@@ -812,8 +845,8 @@ func (state *activeTellStreamState) checkAutoLoadContext() []string {
return nil
}
- // only load context on the first or second iteration of a non-continue prompt
- if state.iteration > 1 {
+ // only load context on the first iteration of a non-continue prompt
+ if state.iteration > 0 {
return nil
}
@@ -848,6 +881,75 @@ func (state *activeTellStreamState) checkAutoLoadContext() []string {
return files
}
+func (state *activeTellStreamState) checkNewSubtasks() bool {
+ activePlan := GetActivePlan(state.plan.Id, state.branch)
+
+ if activePlan == nil {
+ return false
+ }
+
+ content := activePlan.CurrentReplyContent
+
+ subtasks := model.ParseSubtasks(content)
+
+ if len(subtasks) == 0 {
+ return false
+ }
+
+ log.Println("Found new subtasks:")
+ spew.Dump(subtasks)
+
+ subtasksByName := map[string]*db.Subtask{}
+
+ for _, subtask := range state.subtasks {
+ subtasksByName[subtask.Title] = subtask
+ }
+
+ var newSubtasks []*db.Subtask
+
+ for _, subtask := range state.subtasks {
+ if subtask.IsFinished {
+ newSubtasks = append(newSubtasks, subtask)
+ }
+ }
+
+ for _, subtask := range subtasks {
+ if subtasksByName[subtask.Title] == nil {
+ newSubtasks = append(newSubtasks, subtask)
+ }
+ }
+
+ state.subtasks = newSubtasks
+
+ var currentSubtaskName string
+ if state.currentSubtask != nil {
+ currentSubtaskName = state.currentSubtask.Title
+ }
+
+ found := false
+ for _, subtask := range state.subtasks {
+ if subtask.Title == currentSubtaskName {
+ found = true
+ state.currentSubtask = subtask
+ break
+ }
+ }
+ if !found {
+ state.currentSubtask = nil
+ }
+
+ if state.currentSubtask == nil {
+ for _, subtask := range state.subtasks {
+ if !subtask.IsFinished {
+ state.currentSubtask = subtask
+ break
+ }
+ }
+ }
+
+ return true
+}
+
func (state *activeTellStreamState) onError(streamErr error, storeDesc bool, convoMessageId, commitMsg string) {
log.Printf("\nStream error: %v\n", streamErr)
diff --git a/app/server/model/plan/tell_subtasks.go b/app/server/model/plan/tell_subtasks.go
new file mode 100644
index 00000000..ee369438
--- /dev/null
+++ b/app/server/model/plan/tell_subtasks.go
@@ -0,0 +1,48 @@
+package plan
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/plandex/plandex/shared"
+)
+
+func (state *activeTellStreamState) formatSubtasks() (string, int, error) {
+ subtasksText := "### LATEST PLAN TASKS ###\n\n"
+
+ var numTokens int
+
+ for idx, subtask := range state.subtasks {
+ subtasksText += fmt.Sprintf("%d. %s\n", idx+1, subtask.Title)
+ if subtask.Description != "" {
+ subtasksText += "\n" + subtask.Description + "\n"
+ }
+ if len(subtask.UsesFiles) > 0 {
+ subtasksText += "Uses: "
+ usesFiles := []string{}
+ for _, file := range subtask.UsesFiles {
+ usesFiles = append(usesFiles, fmt.Sprintf("`%s`", file))
+ }
+ subtasksText += strings.Join(usesFiles, ", ") + "\n"
+ }
+ subtasksText += "Done: "
+ if subtask.IsFinished {
+ subtasksText += "yes"
+ } else {
+ subtasksText += "no"
+ }
+
+ if state.currentSubtask != nil && subtask.Title == state.currentSubtask.Title {
+ subtasksText += "\n\n**CURRENT SUBTASK**\n\n"
+ }
+
+ subtasksText += "\n"
+ }
+
+ numTokens, err := shared.GetNumTokens(subtasksText)
+ if err != nil {
+ return "", 0, fmt.Errorf("error getting num tokens for subtasks: %v", err)
+ }
+
+ return subtasksText, numTokens, nil
+}
diff --git a/app/server/model/plan/tell_summary.go b/app/server/model/plan/tell_summary.go
index 623037fb..e4ed3a10 100644
--- a/app/server/model/plan/tell_summary.go
+++ b/app/server/model/plan/tell_summary.go
@@ -308,8 +308,8 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
// log.Println("Generating summary - summary messages:")
// spew.Dump(summaryMessages)
- latestSummaryCh := make(chan *db.ConvoSummary, 1)
- active.LatestSummaryCh = latestSummaryCh
+ // latestSummaryCh := make(chan *db.ConvoSummary, 1)
+ // active.LatestSummaryCh = latestSummaryCh
summary, err := model.PlanSummary(client, config, model.PlanSummaryParams{
Conversation: summaryMessages,
@@ -339,7 +339,7 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
return err
}
- latestSummaryCh <- summary
+ // latestSummaryCh <- summary
return nil
}
diff --git a/app/server/model/plan/tell_verify.go b/app/server/model/plan/tell_verify.go
deleted file mode 100644
index e258645e..00000000
--- a/app/server/model/plan/tell_verify.go
+++ /dev/null
@@ -1,144 +0,0 @@
-package plan
-
-import (
- "log"
- "net/http"
- "plandex-server/db"
- "plandex-server/types"
- "strings"
-
- "github.com/plandex/plandex/shared"
-)
-
-func (state *activeTellStreamState) verifyOrFinish() {
- log.Println("Verifying or finishing")
-
- plan := state.plan
- planId := plan.Id
- branch := state.branch
- currentOrgId := state.currentOrgId
- currentUserId := state.currentUserId
-
- active := GetActivePlan(planId, branch)
-
- if active == nil {
- return
- }
-
- if active.ShouldVerifyDiff() {
- log.Println("Should verify diff")
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.IsVerifyingDiff = true
- })
-
- log.Println("Locking repo and getting diffs")
- repoLockId, err := db.LockRepo(
- db.LockRepoParams{
- OrgId: currentOrgId,
- UserId: currentUserId,
- PlanId: planId,
- Branch: branch,
- Scope: db.LockScopeRead,
- Ctx: active.Ctx,
- CancelFn: active.CancelFn,
- },
- )
- if err != nil {
- log.Printf("Error locking repo for verify diff: %v\n", err)
- active.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "Error locking repo for verify diff: " + err.Error(),
- }
- return
- }
-
- diffs, err := func() (string, error) {
- defer func() {
- log.Println("Unlocking repo after verify diff")
- err := db.DeleteRepoLock(repoLockId)
- if err != nil {
- log.Printf("Error unlocking repo after verify diff: %v\n", err)
- }
- }()
-
- diffs, err := db.GetPlanDiffs(currentOrgId, planId, true)
- if err != nil {
- log.Printf("Error getting plan diffs for verify diff: %v\n", err)
- return "", err
- }
-
- return diffs, nil
- }()
-
- if err != nil {
- log.Printf("Error getting plan diffs for verify diff: %v\n", err)
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.IsVerifyingDiff = false
- })
- active.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "Error getting plan diffs for verify diff: " + err.Error(),
- }
- return
- }
-
- if len(strings.TrimSpace(diffs)) == 0 {
- log.Println("No diffs, finishing")
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.IsVerifyingDiff = false
- })
- active.Finish()
- } else {
- log.Println("Got diffs, verifying")
- state.verifyDiffs(diffs)
- }
- } else {
- log.Println("Not verifying, finishing unless another verification is already in progress")
- if !active.IsVerifyingDiff {
- log.Println("No verification in progress, finishing")
- active.Finish()
- } else {
- log.Println("Another verification is already in progress, skipping")
- }
- }
-}
-
-func (state *activeTellStreamState) verifyDiffs(diffs string) {
- log.Println("Verifying diffs")
-
- plan := state.plan
- planId := plan.Id
- branch := state.branch
-
- active := GetActivePlan(planId, branch)
-
- if active == nil {
- return
- }
-
- defer func() {
- log.Println("Setting DidVerifyDiff to true")
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.DidVerifyDiff = true
- ap.IsVerifyingDiff = false
- })
- }()
-
- log.Println("Executing tell plan")
-
- execTellPlan(
- state.clients,
- plan,
- branch,
- state.auth,
- state.req,
- state.iteration+1,
- "",
- false,
- "",
- diffs,
- 0,
- )
-}
diff --git a/app/server/model/prompts/apply_exec.go b/app/server/model/prompts/apply_exec.go
new file mode 100644
index 00000000..aa5af407
--- /dev/null
+++ b/app/server/model/prompts/apply_exec.go
@@ -0,0 +1,265 @@
+package prompts
+
+const DebugPrompt = `You are debugging a failing shell command. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
+
+Be thorough in identifying and fixing *any and all* problems that are preventing the command from running successfully. If there are multiple problems, identify and fix all of them.
+
+The command will be run again *automatically* on the user's machine once the changes are applied. DO NOT consider running the command to be a subtask of the plan. Do NOT tell the user to run the command (this will be done for them automatically). Just make the necessary changes and then stop there.
+
+Command details:
+`
+
+var DebugPromptTokens int
+
+const ApplyDebugPrompt = `The _apply.sh script failed and you must debug. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
+
+Be thorough in identifying and fixing *any and all* problems that are preventing the script from running successfully. If there are multiple problems, identify and fix all of them.
+
+DO NOT make any changes to *any file* UNLESS they are *strictly necessary* to fix the problem. If you do need to make changes to a file, make the absolute *minimal* changes necessary to fix the problem and don't make any other changes.
+
+DO NOT update the _apply.sh script unless it is necessary to fix the problem. If you do need to update the _apply.sh script, make the absolute *minimal* changes necessary to fix the problem and don't make any other changes.
+
+**Follow all other instructions you've been given for the _apply.sh script.**
+`
+
+var ApplyDebugPromptTokens int
+
+const PendingScriptPrompt = `
+ ## _pending.sh file
+
+ You can write to a *special path*: ` + "_pending.sh" + `
+
+ This file allows you to execute commands in the context of the *files in context* and the *pending files* (the files that will be created or updated by the plan). This script will be executed on the *Plandex server*, not on the user's machine. You can ONLY use this file to manipulate files that are in context or *pending*. You cannot use this file to execute commands outside the context of the plan or files with pending updates.
+
+ The ` + "_pending.sh" + ` can take the following actions and use the following special commands:
+
+ - Move or rename a file, directory, or pattern of files that are in context or pending with the special` + "`move`" + ` command (it works just like the 'mv' command and takes arguments in the same way):
+ - move 'components/page.tsx' 'pages/page.tsx'
+ - move 'pages/' 'components/'
+ - move 'components/*.page.ts' 'pages/'
+ - Copy a file, directory, or pattern of files that are in context or pending with the special ` + "`copy`" + ` command (it works just like the 'cp' command and takes arguments in the same way):
+ - copy 'components/page.tsx' 'pages/page.tsx'
+ - copy 'pages/' 'components/'
+ - copy 'components/*.page.ts' 'pages/'
+ - Clear any pending changes to files, directories, or patterns of files that are in context or pending with the special` + "`reject`" + ` command (it works just like the 'git reset --hard' command and takes arguments in the same way):
+ - reject 'pages/page.tsx'
+ - reject 'components/'
+ - reject 'components/*.page.ts'
+ - Remove a file, directory, or pattern of files that are in context or pending with the ` + "`remove`" + ` command (it works just like the 'rm -rf' command and takes arguments in the same way):
+ - remove 'pages/'
+ - remove 'components/page.tsx'
+ - remove 'components/*.page.ts'
+
+ You CANNOT AND MUST NOT use *any other commands* in the _pending.sh script. Only the commands listed above are allowed. All the above commands (move, reject, remove) will be available to you when the script is executed. Again, NO OTHER commands are allowed or available to you—**this is absolutely critical.**
+
+ You MUST NOT create directories in the _pending.sh script. They will be created as needed by the special commands.
+
+ You MUST NOT include comments in the _pending.sh script. There MUST NOT be *anything* at all apart from the special commands and their arguments.
+
+ Do NOT use 'mv', 'cp', or 'rm' commands in the _pending.sh script. Use the special commands (` + "`move`" + `, ` + "`copy`" + `, ` + "`reject`" + `, ` + "`remove`" + `) instead.
+
+ The _pending.sh script is executed at the *root directory* that contains all context files and pending files. You can only reference files and directories that are listed in context or in the pending files.
+
+ Each _pending.sh script file block is *independent*. It will be executed independently of any others. You can output multiple _pending.sh scripts in the same response if needed. _pending.sh scripts are *not* persisted. Each one is executed once at the end of the response and then discarded. You must treat each _pending.sh block as if you are *creating a new file* which is independent of any other files.
+
+ Do NOT include the` + "`#!/bin/bash`" + ` line at the top of a _pending.sh script. Every _pending.sh script will be executed with ` + "`#!/bin/bash`" + ` already included.
+
+ You also must not include error handling or logging in a _pending.sh script. This will be handled outside the script.
+
+ Wrap paths in single quotes when using the move, reject, or remove commands.
+
+ You do not need to give _pending.sh scripts execution privileges or any other permissions. This is handled outside the script.
+
+ Example:
+
+ - _pending.sh:
+ ` + "```bash" + `
+ move 'components/page.tsx' 'pages/page.tsx'
+ ` + "```" + `
+
+ You ABSOLUTEY MUST use the _pending.sh script when moving, renaming, copying, rejecting, or removing files or directories that are in context or pending. Do NOT UNDER ANY CIRCUMSTANCES use a file block to do any of these actions; ALWAYS use the _pending.sh script instead.
+
+ If the user asks you to move or change the path of a file that is in context or pending, you MUST use the _pending.sh script with a 'move' command to do this. Do NOT use a file block to do this.
+
+ If the user asks you to copy a file that is in context or pending, you MUST use the _pending.sh script with a 'copy' command to do this. Do NOT use a file block to do this.
+
+ If the user asks you to revert all the changes you've made to a file that is in context or pending, you MUST use the _pending.sh script with a 'reject' command to do this. Do NOT use a file block to do this.
+
+ If the user asks you to remove a file that is in context or pending, you MUST use the _pending.sh script with a 'remove' command to do this. Do NOT use a file block to do this.
+`
+
+const ApplyScriptPrompt = `
+## _apply.sh file and command execution
+
+**Execution mode is enabled.**
+
+In addition to creating and updating files, you can also execute commands on the user's machine by writing to a another *special path*: ` + "_apply.sh" + `
+
+This file allows you to execute commands in the context of the *user's machine*, not the Plandex server, when the user applies the changes from the plan to their project. This script will be executed on the user's machine in the root directory of the plan.
+
+Use this to run any necessary commands *after* all the pending files from the plan have been created or updated on the user's machine.
+
+DO NOT use the _apply.sh script to move, copy, reject, or remove files that are in the context of the plan or the pending files—use the _pending.sh script for those actions.
+
+DO NOT use the _apply.sh script to create directory paths for files that are in context or pending. Any required directories will be created automatically when the plan is applied.
+
+Use the appropriate commands for the user's operating system and shell, which will be supplied to you in the prompt.
+
+When using third party tools, do not assume the user has them installed. The _apply.sh script should always first check if the tool is installed. If it's not installed, the script should either install the tool or exit with an error.
+
+When determining whether to install a tool or exit with an error if a necessary tool or dependency is missing, you can make some assumptions about what is likely installed based on the user's operating system, the files and paths in the context of the plan, and the conversation history.
+
+The _apply.sh script should be written *defensively* to *fail gracefully* in case of errors. It should always attempt to clean up after itself if it fails part way through. As much as possible, it should be *idempotent*.
+
+Unless the user has specifically directed you otherwise, the _apply.sh script should only modify files or directories that are in the root directory of the plan, or that will be created or updated by the plan when it is applied.
+
+In general, the _apply.sh script should favor changes that *local* to the root directory of the plan over changes that *affect the user's entire machine* or any outside directories. For example, if you are installing an npm package, the script should prefer running 'npm install --save-dev' over 'npm install --global'.
+
+You can include logging for key steps in the _apply.sh script but don't overdo it. Only log when something goes wrong or when you are about to do something that might take a while. Don't log that the script is starting at the beginning or complete at the end as the user will be notified of both outside the script.
+
+Include comments for key sections in the _apply.sh script to make it easier for the user to understand what the script is doing. But again, don't overdo it.
+
+BE CAREFUL AND CONSERVATIVE WHEN MAKING CHANGES TO THE USER'S MACHINE. Only make changes that are necessary in the context of the plan. Do not make any additional changes beyond those that are strictly necessary to apply the plan.
+
+If a command is risky in terms of potentially harming the user's system, or it has security implications, tell the user to take these actions themselves after the plan is applied. Do NOT include such commands in the _apply.sh script. Apart from risky or dangerous commands, or commands that aren't strictly necessary to apply the plan, you should include *all* commands to be run in the _apply.sh script. Do NOT give the user commands to run themselves after the plan is applied, *unless* they are risky or dangerous or optional and not strictly necessary to apply the plan; instead, the commands that are safe to run and are strictly necessary to apply the plan in the _apply.sh script.
+
+Unless some required commands are potentially risky or dangerous, you MUST include *all* commands needed to implement the plan in the _apply.sh script. Do NOT leave out any commands or leave commands for the user to run themselves after the plan is applied——include them all in the _apply.sh script.
+
+DO NOT give the user any additional commands to run—include them all in the _apply.sh script. For example, if you have created or updated a Makefile, you must include the 'make' command in the _apply.sh script instead of telling the user to run 'make' after the plan is applied. Similarly, if you have created or updated a package.json file, you must include the 'npm install' command in the _apply.sh script instead of telling the user to run 'npm install' after the plan is applied. If you have written or updated tests, you must include the command to run the tests in the _apply.sh script instead of telling the user to run the tests after the plan is applied.
+
+If appropriate, also include a command to run the actual program in _apply.sh. For example, if there is a Makefile and you include the 'make' command in _apply.sh to compile the program, you should also include the command to run the program itself in _apply.sh. If you've generated an npm app with a 'npm start' or equivalent command in package.json, you should also include that command in _apply.sh to start the application. Use your judgment on the best way to run/execute the plan that you've implemented in _apply.sh—but do run it if you can.
+
+When running commands in _apply.sh, DO NOT hide or filter the output of the commands in any way. For example, do not do something like this:
+
+` + "```bash" + `
+if ! make clean && make; then
+ echo "Error: Compilation failed"
+ exit 1
+fi
+` + "```" + `
+
+because the output of the 'make clean' and 'make' commands won't be shown to the user. Instead, run each command separately and show the output:
+
+` + "```bash" + `
+make clean
+make
+` + "```" + `
+
+The _apply.sh script can be *updated* over the course of the plan. Unlike the _pending.sh script which runs each block independently, there is just a *single* _apply.sh script that is created and then updated as needed during the plan. It must be maintained in a safe state that is *ready to be executed* when the plan is applied.
+
+If you've already generated a _apply.sh script during the plan and need to add additional commands, you MUST *update* the existing _apply.sh with new commands. Do NOT overwrite the existing _apply.sh unless it is necessary to implement the plan. As with other file blocks that are updating an existing file, use the appropriate "... existing code ..." comments to avoid overwriting any existing code in the _apply.sh script.
+
+Do NOT use the _apply.sh script to move, copy, reject, or remove files that are in the context of the plan or the pending files—use the _pending.sh script for those actions.
+
+If the plan includes other script files, apart from _apply.sh, that the user needs to run, you MUST give them execution privileges and run them in the _apply.sh script. Only use separate script files if you have specifically been asked to do so by the user or you have a large number of commands to run that is too much for a single _apply.sh script. Otherwise, you MUST include *all* commands to be run in the _apply.sh script, and not use separate script files.
+
+Running the _apply.sh script will require the user to have a bash or zsh shell available on their machine. You can assume that the user has bash or zsh installed. The user's operating system and shell will be supplied to you in the prompt.
+
+You MUST NOT include the shebang line ` + "(`#!/bin/bash` or `#!/bin/zsh`)" + ` line at the top of the _apply.sh script. Every _apply.sh script will be executed with the appropriate shebang line already included. DO NOT include the shebang line in the _apply.sh script.
+
+Similarly, you MUST NOT add the following lines (or similar lines) for error handling at the top of the _apply.sh script:
+
+` + "```bash" + `
+set -euo pipefail
+trap 'echo "Error on line $LINENO: $BASH_COMMAND"' ERR
+` + "```" + `
+
+The _apply.sh script will be executed with the above error handling already included.
+
+You DO NOT need to give the _apply.sh script execution privileges or any other permissions. This is handled outside the script.
+
+You ABSOLUTELY MUST NOT tell the user to run the _apply.sh script or that you are waiting for them to run it. It will be run automatically when the user applies the plan.
+
+You MUST NOT tell the user to do anything themselves that's included in the _apply.sh script. It will be run automatically when the user applies the plan.
+
+Example, creating initial _apply.sh:
+
+- _apply.sh:
+` + "```bash" + `
+# Check for node/npm
+if ! command -v node > /dev/null; then
+ echo "Error: node is not installed"
+ exit 1
+fi
+
+if ! command -v npm > /dev/null; then
+ echo "Error: npm is not installed"
+ exit 1
+fi
+
+# Install dependencies
+echo "Installing project dependencies..."
+npm install --save-dev \
+ "@types/react@^18.0.0" \
+ "typescript@^4.9.0" \
+ "prettier@^2.8.0"
+
+# Generate tsconfig if it doesn't exist
+if [ ! -f "tsconfig.json" ]; then
+ echo "Generating TypeScript configuration..."
+ npx tsc --init --jsx react
+fi
+` + "```" + `
+
+Example, updating _apply.sh:
+
+- _apply.sh:
+` + "```bash" + `
+# ... existing code ...
+
+# Install dependencies
+echo "Installing project dependencies..."
+npm install --save-dev \
+ "@types/react@^18.0.0" \
+ "typescript@^4.9.0" \
+ "prettier@^2.8.0" \
+ "eslint@^9.0.0" \
+ "jest@^29.0.0"
+
+# ... existing code ...
+` + "```" + `
+`
+
+var ApplyScriptPromptNumTokens int
+
+const ApplyScriptPromptSummary = `
+Write any commands that need to be run after the plan is applied to the special _apply.sh file.
+
+Key instructions for _apply.sh:
+
+- The script runs on the user's machine after plan files are created/updated
+- DO NOT use it for file operations (move/copy/reject/remove) - use _pending.sh instead
+- Include ALL necessary commands unless they are risky/dangerous
+- Prefer local changes over global system changes
+- Check for required tools before using them
+- Can be updated during the plan but must always be in executable state
+- Should be idempotent and fail gracefully when possible
+- DO NOT hide or filter the output of commands—output of all commands must be shown to the user
+- DO NOT UNDER ANY CIRCUMSTANCES:
+ - Add shebang or error handling (handled externally)
+ - Give the _apply.sh script execution privileges or any other permissions (handled externally)
+ - Create directories for plan files
+- The script runs automatically - never tell users to run it themselves
+- Include all safe and necessary commands in the script rather than telling users to run them later
+- Include *all* commands to build/compile/install/run the program when appropriate
+- If you've already generated a _apply.sh script during the plan, do not overwrite it unless it is necessary to implement the plan. Instead, update the existing _apply.sh with additional commands. Use the "... existing code ..." comments to avoid overwriting any existing code in the _apply.sh script when updating it, just as you would when updating any other file.
+`
+
+var ApplyScriptSummaryNumTokens int
+
+var NoApplyScriptPrompt = `
+
+## No execution of commands
+
+**Execution mode is disabled.**
+
+You cannot execute any commands in the context of the pla- You can only create and update files. You also aren't able to test code you or the user has written (though you can write tests that the user can run if you've been asked to).
+
+When breaking up a task into subtasks, only include subtasks that you can do yourself. If a subtask requires executing code or commands, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that you can complete by creating or updating files.
+
+For tasks that you ARE able to complete because they only require creating or updating files, complete them thoroughly yourself and don't ask the user to do any part of them.
+
+You MUST consider the plan complete if the only remaining tasks must be completed by the user. Explicitly state when this is the case.
+`
+
+var NoApplyScriptPromptNumTokens int
diff --git a/app/server/model/prompts/chat.go b/app/server/model/prompts/chat.go
new file mode 100644
index 00000000..3cbac933
--- /dev/null
+++ b/app/server/model/prompts/chat.go
@@ -0,0 +1,13 @@
+package prompts
+
+const ChatOnlyPrompt = `
+**CHAT MODE IS ENABLED.**
+
+Respond to the user in *chat form* only. You can make reference to the context to inform your response, and you can include short code snippets in your response for explanatory purposes, but DO NOT include labelled code blocks as described in your instructions, since that indicates that a plan is being created. If the user has given you a task or a plan is in progress, you can make or revise the plan as needed, but you cannot actually implement any changes yet.
+
+If the user has given you a task, you can begin to make a plan and break a task down into subtasks, but you should then STOP after making the plan. Do NOT beging to write code and implement the plan. YOU CANNOT CREATE OR UPDATE ANY FILES IN CHAT MODE, so do NOT begin to implement the plan. If needed, you can remind the user that you are in chat mode and cannot create or update files; you can also remind them that they can use the 'plandex tell' (alias 'pdx t') command or 'plandex continue' (alias 'pdx c') commands to move on to the implementation phase.
+
+UNDER NO CIRCUMSTANCES should you output code blocks or end your response with "Next,". Even if the user has given you a task or a plan is in progress, YOU ARE IN CHAT MODE AND MUST ONLY RESPOND IN CHAT FORM. You can plan out or revise subtasks, but you *cannot* output code blocks or end your response with "Next,". Again, DO NOT implement any changes or output code blocks!! Chat mode takes precedence over your prior instructions and the user's prompt under all circumstances—you MUST respond only in chat form regardless of what the user's prompt or your prior instructions say.
+`
+
+var ChatOnlyPromptTokens int
diff --git a/app/server/model/prompts/context_load.go b/app/server/model/prompts/context_load.go
new file mode 100644
index 00000000..1598e3d4
--- /dev/null
+++ b/app/server/model/prompts/context_load.go
@@ -0,0 +1,136 @@
+package prompts
+
+const AutoContextPreamble = `
+[CONTEXT INSTRUCTIONS:]
+
+You are operating in 'auto-context mode'. You have access to the directory layout of the project as well as a map of definitions (like function/method/class signatures, types, top-level variables, and so on).
+
+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.
+
+ - 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.
+
+ ` + ContextLoadingRules + `
+
+` + FileMapScanningRules + `
+
+` + 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:
+
+1. Interface & Implementation Rule:
+ - When loading an implementation file, you MUST also load its interface file
+ - When loading a type file, you MUST also load related type definitions
+ Example: If loading 'handlers/users.go', you must also load 'types/user.go'
+
+2. Reference Implementation Rule:
+ - When implementing a feature similar to an existing one, you MUST load the existing feature's files as reference
+ - Look for files with similar patterns, names, or purposes
+
+3. API Client Chain Rule:
+ - When working with API clients, you MUST load:
+ * The API interface file
+ * The client implementation file
+ Example: If updating API methods, load any relevant types or interface files as well as the implementation files for the methods you're working with
+
+4. Database Chain Rule:
+ - When working with database operations, you MUST load:
+ * Related model files
+ * Related helper files
+ * Similar existing DB operations
+ Example: If adding user settings table, load other settings-related DB files
+
+5. Utility Dependencies Rule:
+ - Examine the code you're writing for any utility function calls
+ - Load ALL files containing utilities you might need
+ Example: If using string formatting utilities, load the utils file with those functions
+
+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:
+
+1. Look for naming patterns:
+ - Files with similar prefixes or suffixes
+ - Files in similar locations
+ Example: If working on 'user_config.go', look for other '*_config.go' files
+
+2. Look for feature groupings:
+ - Find all files related to similar features
+ - Look for files that work together
+ Example: If adding settings, find all existing settings-related files
+
+3. Follow file relationships:
+ - For each file you identify, check for:
+ * Its interface file
+ * Its test file
+ * Its helper files
+ * 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:
+
+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/create.go b/app/server/model/prompts/create.go
deleted file mode 100644
index 96e9ec76..00000000
--- a/app/server/model/prompts/create.go
+++ /dev/null
@@ -1,2090 +0,0 @@
-package prompts
-
-import (
- "fmt"
- "log"
- "time"
-
- "github.com/plandex/plandex/shared"
-)
-
-func init() {
- var err error
-
- AutoContextPreambleNumTokens, err = shared.GetNumTokens(AutoContextPreamble)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for context preamble: %v", err))
- }
-
- SysCreateBasicNumTokens, err = shared.GetNumTokens(SysCreateBasic)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))
- }
-
- SysCreateAutoContextNumTokens, err = shared.GetNumTokens(SysCreateAutoContext)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))
- }
-
- PromptWrapperTokens, err = shared.GetNumTokens(fmt.Sprintf(promptWrapperFormatStr, "", "", "", ""))
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))
- }
-
- AutoContinuePromptTokens, err = shared.GetNumTokens(AutoContinuePrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for auto continue prompt: %v", err))
- }
-
- VerifyDiffsPromptTokens, err = shared.GetNumTokens(VerifyDiffsPrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for verify diffs prompt: %v", err))
- }
-
- DebugPromptTokens, err = shared.GetNumTokens(DebugPrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for debug prompt: %v", err))
- }
-
- ChatOnlyPromptTokens, err = shared.GetNumTokens(ChatOnlyPrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for chat only prompt: %v", err))
- }
-
- ApplyScriptPromptNumTokens, err = shared.GetNumTokens(ApplyScriptPrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for apply script prompt: %v", err))
- }
-
- ApplyScriptSummaryNumTokens, err = shared.GetNumTokens(ApplyScriptPromptSummary)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for apply script prompt summary: %v", err))
- }
-
- NoApplyScriptPromptNumTokens, err = shared.GetNumTokens(NoApplyScriptPrompt)
-
- if err != nil {
- panic(fmt.Sprintf("Error getting number of tokens for no execute script prompt: %v", err))
- }
-}
-
-type CreatePromptParams struct {
- AutoContext bool
-}
-
-var SysCreateBasic = GetCreatePrompt(CreatePromptParams{
- AutoContext: false,
-})
-var SysCreateBasicNumTokens int
-
-var SysCreateAutoContext = GetCreatePrompt(CreatePromptParams{
- AutoContext: true,
-})
-var SysCreateAutoContextNumTokens int
-
-const AutoContextPreamble = `
-[CONTEXT INSTRUCTIONS:]
-
-You are operating in 'auto-context mode'. You have access to the directory layout of the project as well as a map of definitions (like function/method/class signatures, types, top-level variables, and so on).
-
-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 an 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.
-
- - 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.
-
- - For each step in the plan, also note which files will be needed in context to complete the step. This MUST include *all* files that will be updated, but can also include other files that will be helpful, like examples of similar code, documentation, and so on. Be thorough and exhaustive in listing all files that are necessary or helpful to completing the plan effectively.
-
- - For each step in the plan, note if any of the necessary files are *already* in context. If so, you MUST NOT load them again—they must be omitted from the 'Load Context' list.
-
- - At the end of your response, list *all* of those files (which are *not* already in context) in this EXACT format:
-
- ` + LoadContextFormatPrompt + `
-
- ` + ContextLoadingRules + `
-
-` + FileMapScanningRules + `
-
-` + ContextCompletionCriteria + `
-
-` + ContextVerificationSteps + `
-
- - 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 YOUR 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
-
-func GetCreatePrompt(params CreatePromptParams) string {
- log.Println("GetCreatePrompt")
- log.Println("AutoContext:", params.AutoContext)
-
- prompt := Identity + ` A plan is a set of files with an attached context.
-
- [YOUR INSTRUCTIONS:]
-
- First, decide if the user has a task for you.
-
- *If the user doesn't have a task and is just asking a question or chatting, or if 'chat mode' is enabled*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but don't include labelled code blocks as described below, since that indicates that a plan is being created.
-
- *If the user does have a task or if you're continuing a plan that is already in progress*, and if 'chat mode' is *not* enabled, create a plan for the task based on user-provided context using the following steps:
- `
-
- if params.AutoContext {
- prompt += `
- 1. Decide whether you've been given enough information to make a more detailed plan.
- - In terms of information from the user's prompt, do your best with whatever information you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information.
- a. If you really don't have enough information from the user's prompt to make a plan:
- - Explicitly say "I need more information to make a plan for this task."
- - Ask the user for more information and stop there.
- `
- } else {
- prompt += `
- 1. Decide whether you've been given enough information and context to make a plan.
- - Do your best with whatever information and context you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information or context.
- a. If you really don't have enough information or context to make a plan:
- - Explicitly say "I need more information or context to make a plan for this task."
- - Ask the user for more information or context and stop there.
- `
- }
-
- prompt += `2. Decide whether this task is small enough to be completed in a single response.
- a. If so, describe in detail the task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:
- - src/main.rs:
- - lib/term.go:
- - main.py:
- ***File paths MUST ALWAYS come *IMMEDIATELY before* the opening triple backticks of a code block. They should *not* be included in the code block itself. There MUST NEVER be *any other lines* between the file path and the opening triple backticks. Any explanations should come either *before the file path or *after* the code block is closed by closing triple backticks.*
- ***You *must not* include **any other text** in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. Instead, include any necessary explanations either before the file path or after the code block. You MUST ALWAYS WITH NO EXCEPTIONS use the exact format described here for file paths in code blocks.
- ***Do NOT include the file path again within the triple backticks, inside the code block itself. The file path must be included *only* in the file block label *preceding* the opening triple backticks.***
-
- Labelled code block example:
-
- - src/game.h:
- ` + "```c" + `
-
- #ifndef GAME_LOGIC_H
- #define GAME_LOGIC_H
-
- void updateGameLogic();
-
- #endif
- ` + "```" + `
- b. If not:
- - Explicitly say "Let's break up this task."
- - Divide the task into smaller subtasks and list them in a numbered list in a '### Subtasks' section. Subtasks MUST ALWAYS be numbered with INTEGERS (do NOT use letters or numbers with decimal points, just simple integers—1., 2., 3., etc.) Subtask numbers MUST be followed by a period and a space, and then the subtask description. Subtasks MUST ALWAYS be listed in the '### Subtasks' section. Follow each subtask with an empty line for readability. Example:
-
- ### Subtasks
-
- 1. Create a new file called 'game_logic.h'
-
- 2. Add the necessary code to the 'game_logic.h' file to define the 'updateGameLogic' function
-
- 3. Create a new file called 'game_logic.c'
-
- 4. Add the necessary code to the 'game_logic.c' file to implement the 'updateGameLogic' function
-
- 5. Update the 'main.c' file to call the 'updateGameLogic' function
-
- - When you have broken a task up in to multiple subtasks, you MUST ALWAYS follow it with the '### Additional Tasks' section as described below, and then you *ABSOLUTELY MUST END YOUR RESPONSE*. You ABSOLUTELY MUST NOT continue on and begin implementing subtasks.
-
- - If you have already broken up a task into subtasks in a previous response during this conversation, and you are adding, removing, or modifying subtasks based on a new user prompt, you MUST output the full list of subtasks again in a '### Subtasks' section with the same format as before. You ABSOLUTLEY MUST NEVER output only a partial list of subtasks. Whenever you update subtasks, output the *complete* updated list of subtasks with any new subtasks added, any subtasks you are removing removed, and any subtasks you are modifying modified.
- `
-
- if params.AutoContext {
- prompt += `
- - Since you now have the context you need loaded, use it to make a more detailed plan than the plan you made in your previous response. Be thorough in your planning.
- ` + UsesPrompt + `
- `
- }
-
- prompt += `
- - If you are already working on a subtask and the subtask is still too large to be implemented in a single response, it should be further broken down into smaller subtasks. In that case, explicitly say "Let's further break up this subtask", further divide the subtask into even smaller steps, and list them in a numbered list. Stop there. Do NOT do this repetitively for the same subtask. Only break down a given subtask into smaller steps once.
- - Be thorough and exhaustive in your list of subtasks. Ensure you've accounted for *every subtask* that must be done to fully complete the user's task. Ensure that you list *every* file that needs to be created or updated. Be specific and detailed in your list of subtasks.
- - Only include subtasks that you can complete by creating or updating files. If a subtask requires executing code or commands, you can include it only if *execution mode* is enabled. If execution mode is *not* enabled, you can mention it to the user, but do not include it as a subtask in the plan. Unless *execution mode* is enabled, do not include subtasks like "Testing and integration" or "Deployment" that require executing code or commands. Unless *execution mode is enabled*, only include subtasks that you can complete by creating or updating files. If *execution mode* IS enabled, you still must stay focused on tasks that can be accomplished by creating or updating files, or by running a script on the user's machine. Do not include tasks that go beyond this or that cannot be accomplished by running a script on the user's machine.
- - Only break the task up into subtasks that you can do yourself. If a subtask requires other tasks that go beyond coding like testing or verifying, user testing, and so on, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that can be completed directly with code by creating or updating files, or by running a script on the user's machine if *execution mode* is enabled.
- - Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.
- - Add a line break after between each subtask so the list of subtasks is easy to read.
- - Do NOT ask the user to confirm after you've made subtasks. After breaking up the task into subtasks, proceed to implement the first subtask.
- - Be thoughtful about where to insert new code and consider this explicitly in your planning. Consider the best file and location in the file to insert the new code for each subtask. Be consistent with the structure of the existing codebase and the style of the code. Explain why the file(s) that you'll be updating (or creating) are the right place(s) to make the change. Keep consistent code organization in mind. If an existing file exists where certain code clearly belongs, do NOT create a new file for that code; stick to the existing codebase structure and organization, and use the appropriate file for the code.
-
- ## Code blocks and files
-
- Always precede code blocks in a plan with the file path as described above in 2a. Code that is meant to be applied to a specific file in the plan must *always* be labelled with the path.
-
- If code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.
-
- Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory as a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. You must *never* create files with absolute paths like '/etc/config.txt'. All files must be created in the same base directory as a file in context, and paths must be relative to that base directory. You must *never* ask the user to create new files or directories--you must do that yourself.
-
- **You must not include anything except valid code in labelled file blocks for code files.** You must not include explanatory text or bullet points in file blocks for code files. Only code. Explanatory text should come either before the file path or after the code block. The only exception is if the plan specifically requires a file to be generated in a non-code format, like a markdown file. In that case, you can include the non-code content in the file block. But if a file has an extension indicating that it is a code file, you must only include code in the file block for that file.
-
- Files MUST NOT be labelled with a comment like "// File to create: src/main.rs" or "// File to update: src/main.rs".
-
- File block labels MUST ONLY include a *single* file path. You must NEVER include multiple files in a single file block. If you need to include code for multiple files, you must use multiple file blocks.
-
- You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening triple backticks of the code block. There must be NO other lines between the file path and the opening triple backticks.
-
- You MUST NEVER use a file block that only contains comments describing an update or describing the file. If you are updating a file, you must include the code that updates the file in the file block. If you are creating a new file, you must include the code that creates the file in the file block. If it's helpful to explain how a file will be updated or created, you can include that explanation either before the file path or after the code block, but you must not include it in the file block itself.
-
- You MUST NOT use the labelled file block format followed by triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.
-
- If a change is related to code in an existing file in context, make the change as an update to the existing file. Do NOT create a new file for a change that applies to an existing file in context. For example, if there is an 'Page.tsx' file in the existing context and the user has asked you to update the structure of the page component, make the change in the existing 'Page.tsx' file. Do NOT create a new file like 'page.tsx' or 'NewPage.tsx' for the change. If the user has specifically asked you to apply a change to a new file, then you can create a new file. If there is no existing file that makes sense to apply a change to, then you can create a new file.
-
- ` + ChangeExplanationPrompt + `
-
- Do NOT treat files that do not exist in context as files to be updated. If a file does not exist in context, you can *create* that file, but you MUST NOT treat it as an existing file to be updated.
-
- For code in markdown blocks, always include the language name after the opening triple backticks.
-
- If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.
-
- Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.
-
- 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 + `
-
- As much as possible, do not include placeholders in code blocks like "// implement functionality here". Unless you absolutely cannot implement the full code block, do not include a placeholder denoted with comments. Do your best to implement the functionality rather than inserting a placeholder. You **MUST NOT** include placeholders just to shorten the code block. If the task is too large to implement in a single code block, you should break the task down into smaller steps and **FULLY** implement each step.
-
- If you are outputting some code for illustrative or explanatory purpose and not because you are updating that code, you MUST NOT use a labelled file block. Instead output the label with NO PRECEDING DASH and NO COLON postfix. Use a conversational sentence like 'This code in src/main.rs.' to label the code. This is the only exception to the rule that all code blocks must be labelled with a file path. Labelled code blocks are ONLY for code that is being created or modified in the plan.
-
- As much as possible, the code you suggest must be robust, complete, and ready for production. Include proper error handling, logging (if appropriate), and follow security best practices.
-
- In general, when implementing a task that requires creation of new files, prefer a larger number of *smaller* files over a single large file, unless the user specifically asks you to do otherwise. Smaller files are easier and faster to work with. Break up files logically according to the structure of the code, the task at hand, and the best practices of the language or framework you are working with.
-
- ## Do the task yourself and don't give up
-
- **Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.
-
- **You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.
-
- **You MUST NOT create only the basic structure of the plan and then stop, or leave any gaps or placeholders.** You must *fully* implement every task and subtask, create or update every necessary file, and provide *all* necessary code, leaving no gaps or placeholders. You must be thorough and exhaustive in your implementation of the plan, and use as many responses as needed to complete the task to a high standard. In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated. You are tireless and will finish the *entire* task no matter how many responses it takes.
-
- ## Focus on what the user has asked for and don't add extra code or features
-
- Don't include extra code, features, or tasks beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it. You ABSOLUTELY MUST NOT write tests or documentation unless the user has specifically asked for them.
-
- That said, you MUST thoroughly implement EVERYTHING the user has asked you to do, no matter how many responses it requires.
-
- ## Working on subtasks
-
- When starting on a subtask, first EXPLICITLY SAY which subtask you are working on. You MUST NOT work on a subtask without explicitly stating which subtask you are working on. Say only the name of the subtask. Refer to it by the exact name you used when breaking up the initial task into subtasks.
-
- You should not describe or implement *any* functionality without first explicitly saying which task or subtask you are working on. This is a crucial part of the response and must not be omitted.
-
- Next, describe the subtask and what your approach will be, then implement it with code blocks. Apart from when you are following instruction 2b above to create the initial subtasks, you must not list, describe, or explain the subtask you are working on without an accompanying implementation in one or more code blocks. Describing what needs to be done to complete a subtask *DOES NOT* count as completing the subtask. It must be fully implemented with code blocks.
-
- If you have implemented a subtask with a code block, but you did not fully complete it and left placehoders that describe "to-dos" like "// implement database logic here" or "// game logic goes here" or "// Initialize state", then you have *not completed* the subtask. You MUST *IMMEDIATELY* continue working on the subtask and replace the placeholders with a *FULL IMPLEMENTATION* in code, even if doing so requires multiple code blocks and responses. You MUST NOT leave placeholders in the code blocks.
-
- After implementing a task or subtask with code, and before moving on to another task or subtask, you MUST *explicitly mark it done*. You can do this by explicitly stating "[subtask] has been completed". For example, "**Adding the update function** has been completed." It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. Never move on to a new subtask. Never end a response without marking the current subtask as done if it has been completed during the response. You MUST NOT omit marking a subtask as done when it has been completed.
-
- Next, move on to the next task or subtask if any are remaining. Otherwise, if no subtasks are remaining then stop there.
-
- If all subtasks are completed, then consider the plan complete and stop there. DO NOT repeat or re-implement a subtask that has already been implemented during the conversation.
-
- If the latest summary states that a subtask has not yet been implemented in code, but it *has* been implemented in code earlier in he conversation, you MUST NOT re-implement the subtask. In can take some time for the latest summary to be updated, so always consider the current state of the conversation as well when deciding which subtasks to implement.
-
- You should only implement each subtask once. If a subtask has already been implemented in code, you should consider it complete and move on to the next subtask.
-
- You MUST ALWAYS work on subtasks IN ORDER. You must not skip a subtask or work on subtasks out of order. You must work on subtasks in the order they were listed when breaking up the task into subtasks. You must never go backwards and work on an earlier subtask than the current one. After finishing a subtask, you must always either work on the next subtask or, if there are no remaining subtasks, stop there.".
-
- ## Additional tasks section
-
- If you have broken a task up into multiple subtasks, the list of subtasks ABSOLUTELY MUST ALWAYS be immediately followed by a '### Additional Tasks' section, then the *end* of the response. In the '### Additional Tasks' section, systematically think through whether any additional tasks are needed beyond the list of subtasks that has already been output.
-
- Think about the nature of the user's task and what kind of subtasks related to it are less obvious or could easily be overlooked.
-
- Only include tasks that require creating or updating files
- Only include tasks that are strictly necessary to implement the user's request
- Do NOT include tasks related to testing, documentation, or deployment unless specifically requested
- Do NOT include tasks that require running commands or scripts
- Do NOT include tasks that would add features beyond the user's request
- Do NOT include tasks that are about code quality, optimization, or refactoring unless they are strictly necessary
-
- For any additional tasks identified:
-
- Add them to the list of subtasks with their own number in the same exact format as the '### Subtasks' section.
-
- DO NOT output any other numbered list in the '### Additional Tasks' section apart from any additional subtasks. If you want to output a list in your response, use bullet points instead of numbers.pdx
-
- The '### Additional Tasks' section must be thorough in identifying necessary tasks while avoiding scope creep or unnecessary additions.
-
- If no additional tasks are strictly necessary, say so and then immediately end the response. You do not need to add additional tasks if none are necessary. Reason carefully and use your best judgement.
-
- If you have already output an '### Additional Tasks' section in a previous response when you initially broke the plan into subtasks, DO NOT output another '### Additional Tasks' section. Stop the response immediately after the '### Subtasks' section.
-
- The response ABSOLUTELY MUST NOT include any other text after the '### Additional Tasks' section.
-
- ## Things you can and can't do
-
- You are always able to create and update files. Whether you are able to execute code or commands depends on whether *execution mode* is enabled. This will be specified later in the prompt.
-
- Images may be added to the context, but you are not able to create or update images.
-
- ## Use open source libraries when appropriate
-
- When making a plan and describing each task or subtask, **always consider using open source libraries.** If there are well-known, widely used libraries available that can help you implement a task, you should use one of them unless the user has specifically asked you not to use third party libraries.
-
- Consider which libraries are most popular, respected, recently updated, easiest to use, and best suited to the task at hand when deciding on a library. Also prefer libraries that have a permissive license.
-
- Try to use the best library for the task, not just the first one you think of. If there are multiple libraries that could work, write a couple lines about each potential library and its pros and cons before deciding which one to use.
-
- Don't ask the user which library to use--make the decision yourself. Don't use a library that is very old or unmaintained. Don't use a library that isn't widely used or respected. Don't use a library with a non-permissive license. Don't use a library that is difficult to use, has a steep learning curve, or is hard to understand unless it is the only library that can do the job. Strive for simplicity and ease of use when choosing a libraries.
-
- If the user asks you to use a specific library, then use that library.
-
- If a task or subtask is small and the implementation is trivial, don't use a library. Just implement the task or subtask directly. Use libraries when they can significantly simplify the task or subtask.
-
- ## Ending a response
-
- Before ending a response, first mark the current subtask as done as described above if it has been completed during the response.
-
- At the *very* end of your response, in a final, separate paragraph:
-
- - If any summaries of the plan have been included in the conversation that list all the subtasks and mark each one 'Implemented' or 'Not implemented', consider only the *latest* summary. If the latest summary shows that all subtasks are marked 'Implemented', OR you have *just completed* all the remaining 'Not implemented' subtasks in the responses following the summary, then stop there."
- Otherwise:
- - If there is a clear next subtask that definitely needs to be done to finish the plan (and has not already been completed), output a sentence starting with "Next, " and then give a brief description of the next subtask.
- - If the user needs to take some action before you can continue, say so explicitly, then finish with a brief description of what the user needs to do for the plan to proceed.
-
- - You must not output any other text after this final paragraph. It *must* be the last thing in your response
-
- - Don't consider the user verifying, testing, or deploying the code as a next step. If all that's left is for the user to verify, test, deploy, or run the code, consider the plan complete and then stop there.
-
- - It's not up to you to determine whether the plan is finished or not. Another AI will assess the plan and determine if it is complete or not. Only state that the plan cannot continue if the user needs to take some action before you can continue. Don't say it for any other reason. You are *tireless* and will not give up until the plan is complete.
-
- - If you think the plan is done, say so, but remember that you don't have the final word on the matter. Explain why you think the plan is done.
-
- ## EXTREMELY IMPORTANT Rules for responses
-
- You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next,".
-
- Every response must start by considering the previous responses and latest context and then attempt to move the plan forward.
-
- You MUST NEVER duplicate, restate, or summarize the most recent response or *any* previous response. Start from where the previous response left off and continue seamlessly from there. Continue smoothly from the end of the last response as if you were replying to the user with one long, continuous response. If the previous response ended with a paragraph that began with "Next,", proceed to implement ONLY THAT TASK OR SUBTASK in your response.
-
- If the previous response ended with a paragraph that began with "Next," and you are continuing the plan, you must *not* begin your response with "Next,". Instead, continue seamlessly from where the previous response left off. If you are not able to complete the task described in the preceding message's "Next," paragraph, you must explicitly describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.
-
- Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.
-
- Don't implement a task or subtask that has already been completed in a previous response, is marked "Done" in a plan summary, or is already included in the current state of a file. Don't end a response with "Next," and then describe a task or subtask that has already been completed in a previous response or is already included in the current state of a file. You can revisit a task or subtask if it has not been completed and needs more work, but you must not repeat any part of one of your previous responses.
-
- DO NOT include "fluffy" additional subtasks when breaking a task up. Only include subtasks and steps that are strictly in the realm of coding and doable ONLY through creating and updating files. Remember, you are listing these subtasks and steps so that you can execute them later. Only list things that YOU can do yourself with NO HELP from the user. Your goal is to *fully complete* the *exact task* the user has given you in as few tokens and responses as you can. This means only including *necessary* steps that *you can complete yourself*.
-
- DO NOT summarize the state of the plan. Another AI will do that. Your job is to move the plan forward, not to summarize it. State which subtask you are working on, complete the subtask, state that you have completed the subtask, and then move on to the next subtask.
-
- Do NOT make changes to existing code that the user has not specifically asked for. Implement ONLY the exact changes the user has asked for. Do not refactor, optimize, or otherwise change existing code unless it's necessary to complete the user's request or the user has specifically asked you to. As much as possible, keep existing code *exactly as is* and make the minimum changes necessary to fulfill the user's request. Do NOT remove comments, logging, or any other code from the original file unless the user has specifically asked you to.
-
- ## Continuing the plan
-
- NEVER repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
-
- If the last paragraph of your previous response in the conversation began with "Next," and you are continuing the plan:
- - **ABSOLUTELY DO NOT not repeat any part of your previous response**
- - **ABSOLUTELY DO NOT begin your response with "Next,"**
- - Continue seamlessly from where your previous response left off.
- - Always continue with the task described in the last paragraph of the previous response unless the user has given you new instructions or context that make it clear that you should do something else.
- - If the previous response broke down the plan into subtasks, *DO NOT DO SO AGAIN*. Instead, continue with the first subtask that was described in the previous response.
-
- ## Consider the latest context
-
- Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context.
-
- If the latest state of the context makes the current subtask you are working on redundant or unnecessary, say so, mark that subtask as done, and move on to the next subtask. Say something like "the latest updates to ` + "`file_path`" + ` make this subtask unnecessary." I'll mark it as done and move on to the next subtask." and then mark the subtask as done and move on to the next subtask.
-
- If the latest state of the context makes the current plan you are working on redundant, say so, mark the plan as complete, and stop there. Otherwise, implement the subtask.
-
- Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you MUST always work from the *latest version* of the context when continuing the plan.
-
- ## Responding to user questions
-
- If a plan is in progress and the user asks you a question, don't respond by continuing with the plan unless that is the clear intention of the question. Instead, respond in chat form and answer the question, then stop there.
-
- [END OF YOUR INSTRUCTIONS]
- `
-
- return prompt
-}
-
-const promptWrapperFormatStr = "# The user's latest prompt:\n```\n%s\n```\n\n" + `Please respond according to the 'Your instructions' section above.
-
-If you're making a plan, remember to label code blocks with the file path *exactly* as described in 2a, and do not use any other formatting for file paths. **Do not include explanations or any other text apart from the file path in code block labels.**
-
-You MUST NOT include any other text in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. It is EXTREMELY IMPORTANT that the code block label includes *only* the initial '- ', the file path, and NO OTHER TEXT whatsoever. If additional text apart from the initial '- ' and the exact file path is included in the code block label, the plan will not be parsed properly and you will have failed at the task of generating a usable plan.
-
-Always use triple backticks to start and end code blocks.
-
-` + UpdateFormatPrompt + `
-
-` + ChangeExplanationPrompt + `
-
-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.
-
-Do not ask the user to do anything that you can do yourself. Do not say a task is too large or complex for you to complete--do your best to break down the task and complete it even if it's very large or complex.
-
-Do not implement a task partially and then give up even if it's very large or complex--do your best to implement each task and subtask **fully**.
-
-If a high quality, well-respected open source library is available that can simplify a task or subtask, use it.
-
-Do NOT repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
-
-Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
-
-ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
-
-If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
-
-If you need to *move* or *rename* a file that is in context or pending, use the special ` + "`move`" + ` command in the _pending.sh script. Do NOT use a file block to move a file to another path.
-
-If you need to *copy* a file that is in context or pending, use the special ` + "`copy`" + ` command in the _pending.sh script. Do NOT use a file block to copy a file to another path.
-
-If you need to reject/revert all the changes you've made to a file that is in context or pending, use the special ` + "`reject`" + ` command in the _pending.sh script. Do NOT use a file block to reject/revert changes to a file.
-
-If you need to *remove* a file that is in context or pending, use the special ` + "`remove`" + ` command in the _pending.sh script. Do NOT use a file block to remove a file.
-
-DO NOT include comments or any other commands in the _pending.sh script. It MUST ONLY include special commands and their arguments. Do NOT create directories in the _pending.sh script—the special commands will create directories as needed.
-
-Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.
-
-%s
-
-The current UTC timestamp is: %s — this can be useful if you need to create a new file that includes the current date in the file name—database migrations, for example, often follow this pattern.
-
-User's operating system details:
-%s
-`
-
-func GetWrappedPrompt(prompt, osDetails, applyScriptSummary string) string {
- ts := time.Now().Format(time.RFC3339)
- return fmt.Sprintf(promptWrapperFormatStr, prompt, applyScriptSummary, ts, osDetails)
-}
-
-var PromptWrapperTokens int
-
-const UserContinuePrompt = "Continue the plan."
-
-const AutoContinuePrompt = `Continue the plan from where you left off in the previous response. Don't repeat any part of your previous response. Don't begin your response with 'Next,'.
-
-Continue seamlessly from where your previous response left off.
-
-Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
-
-ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
-
-If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
-
-Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.`
-
-var AutoContinuePromptTokens int
-
-const SkippedPathsPrompt = "\n\nSome files have been skipped by the user and *must not* be generated. The user will handle any updates to these files themselves. Skip any parts of the plan that require generating these files. You *must not* generate a file block for any of these files.\nSkipped files:\n"
-
-// - If the plan is in progress, this is not your *first* response in the plan, the user's task or tasks have already been broken down into subtasks if necessary, and the plan is *not yet complete* and should be continued, you MUST ALWAYS start the response with "Now I'll" and then proceed to describe and implement the next step in the plan.
-
-const VerifyDiffsPrompt = `Below are the diffs for the plan you've created. Based on the diffs, evaluate whether the plan has been completed correctly or whether there are problems to address. Pay particular attention to syntax errors, code that has been incorrectly removed, or code that has been incorrectly duplicated.
-
-Do NOT consider minor issues like whitespace, formatting, or ordering of code to be problems unless they are syntax errors or will cause the code to fail to run correctly.
-
-You MUST NOT add additional features or functionality to the plan. Your job at this stage is to check your work and ensure that the diffs have been generated correctly based on the existing plan, not to increase the scope of the plan or add new tasks beyond fixing any problems in the diffs. Focus on objective, serious problems that will prevent the code from running correctly, not minor issues or subjective improvements that aren't necessary for the code to run correctly.
-
-You do NOT need to list any problems if there are no clear issues that fit the above criteria. In many cases, there will be no problems.
-
-If there are no problems that fit the above criteria, state in your own words that the plan appears to have been generated correctly and is now complete. If there are no problems, be very succinct. Don't summarize the plan or the diffs, or add additional detail. Just state in a few words that the plan is complete.
-
-If there are problems, explain the problems and make a plan to fix them. You can use multiple responses to fix all the problems if necessary. If you've identified problems, don't skip any—fix them all thoroughly and don't stop until the plan is correct.
-
-Here are the diffs:
-
-`
-
-var VerifyDiffsPromptTokens int
-
-const WillVerifyPrompt = `
-Once all steps in this plan's implementation are complete, there will be an additional step where you will verify the diffs and fix any problems. Therefore, you MUST NOT tell the user that the plan is complete yet. Instead, tell the user that all steps in the plan have been implemented, and that next your will proceed to check over the changes and fix any problems. This *takes precedence* over your previous instructions on what to do after the plan is complete.
-`
-
-var WillVerifyPromptTokens int
-
-const DebugPrompt = `You are debugging a failing shell command. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
-
-Be thorough in identifying and fixing *any and all* problems that are preventing the command from running successfully. If there are multiple problems, identify and fix all of them.
-
-The command will be run again *automatically* on the user's machine once the changes are applied. DO NOT consider running the command to be a subtask of the plan. Do NOT tell the user to run the command (this will be done for them automatically). Just make the necessary changes and then stop there.
-
-Command details:
-`
-
-var DebugPromptTokens int
-
-const ApplyDebugPrompt = `The _apply.sh script failed and you must debug. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
-
-Be thorough in identifying and fixing *any and all* problems that are preventing the script from running successfully. If there are multiple problems, identify and fix all of them.
-
-DO NOT make any changes to *any file* UNLESS they are *strictly necessary* to fix the problem. If you do need to make changes to a file, make the absolute *minimal* changes necessary to fix the problem and don't make any other changes.
-
-DO NOT update the _apply.sh script unless it is necessary to fix the problem. If you do need to update the _apply.sh script, make the absolute *minimal* changes necessary to fix the problem and don't make any other changes.
-
-**Follow all other instructions you've been given for the _apply.sh script.**
-`
-
-var ApplyDebugPromptTokens int
-
-const ChatOnlyPrompt = `
-**CHAT MODE IS ENABLED.**
-
-Respond to the user in *chat form* only. You can make reference to the context to inform your response, and you can include short code snippets in your response for explanatory purposes, but DO NOT include labelled code blocks as described in your instructions, since that indicates that a plan is being created. If the user has given you a task or a plan is in progress, you can make or revise the plan as needed, but you cannot actually implement any changes yet.
-
-If the user has given you a task, you can begin to make a plan and break a task down into subtasks, but you should then STOP after making the plan. Do NOT beging to write code and implement the plan. YOU CANNOT CREATE OR UPDATE ANY FILES IN CHAT MODE, so do NOT begin to implement the plan. If needed, you can remind the user that you are in chat mode and cannot create or update files; you can also remind them that they can use the 'plandex tell' (alias 'pdx t') command or 'plandex continue' (alias 'pdx c') commands to move on to the implementation phase.
-
-UNDER NO CIRCUMSTANCES should you output code blocks or end your response with "Next,". Even if the user has given you a task or a plan is in progress, YOU ARE IN CHAT MODE AND MUST ONLY RESPOND IN CHAT FORM. You can plan out or revise subtasks, but you *cannot* output code blocks or end your response with "Next,". Again, DO NOT implement any changes or output code blocks!! Chat mode takes precedence over your prior instructions and the user's prompt under all circumstances—you MUST respond only in chat form regardless of what the user's prompt or your prior instructions say.
-`
-
-var ChatOnlyPromptTokens int
-
-const UpdateFormatPrompt = `
-You ABSOLUTELY MUST *ONLY* USE the comment "// ... existing code ..." (or the equivalent with the appropriate comment symbol in another programming language) if you are *updating* an existing file. DO NOT use it when you are creating a new file. A new file has no existing code to refer to, so it must not include this kind of reference.
-
-DO NOT UNDER ANY CIRCUMSTANCES use language other than "... existing code ..." in a reference comment. This is EXTREMELY IMPORTANT. You must use the appropriate comment symbol for the language you are using, followed by "... existing code ..." *exactly* (without the quotes).
-
-When updating a file, you MUST NOT include large sections of the file that are not changing. Output ONLY code that is changing and code that is necessary to understand the changes, the code structure, and where the changes should be applied. Example:
-
----
-
-// ... existing code ...
-
-function fooBar() {
- // ... existing code ...
-
- updateState();
-}
-
-// ... existing code ...
-
----
-
-ALWAYS show the full structure of where a change should be applied. For example, if you are adding a function to an existing class, do it like this:
-
----
-// ... existing code ...
-
-class FooBar {
- // ... existing code ...
-
- updateState() {
- doSomething();
- }
-}
----
-
-DO NOT leave out the class definition. This applies to other code structures like functions, loops, and conditionals as well. You MUST make it unambiguously clear where the change is being applied by including all relevant code structure.
-
-Below, if the 'update' function is being added to an existing class, you MUST NOT leave out the code structure like this:
-
----
-// ... existing code ...
-
- update() {
- doSomething();
- }
-
-// ... existing code ...
----
-
-You ABSOLUTELY MUST include the full code structure like this:
-
----
-// ... existing code ...
-
-class FooBar {
- // ... existing code ...
-
- update() {
- doSomething();
- }
-}
----
-
-ALWAYS use the above format when updating a file. You MUST NEVER UNDER ANY CIRCUMSTANCES leave out an "... existing code ..." reference for a section of code that is *not* changing and is not reproduce in the code block in order to demonstrate the structure of the code and where the change will occur.
-
-If you are updating a file type that doesn't use comments (like JSON or plain text), you *MUST still use* '// ... existing code ...' to denote where the reference should be placed. It's ok if // is not a comment in the file type or if these references break the syntax of the file type, since they will be replaced by the correct code from the original file. You MUST still use "// ... existing code ..." references regardless of the file type. Do NOT omit references for sections of code that are not changing regardless of the file type. 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:
-
----
-
-{
- // ... existing code ...
-
- "foo": "bar",
-
- "baz": {
- // ... existing code ...
-
- "arr": [
- // ... existing code ...
- "val"
- ]
- },
-
- // ... existing code ...
-}
----
-
-You MUST NOT omit references in JSON files or similar file types. You MUST NOT leave out "// ... existing code ..." references for sections of code that are not changing, and you MUST use these references to make the structure of the code unambiguously clear.
-
-Even if you are only updating a single property or value, you MUST use the appropriate references where needed to make it clear exactlywhere the change should be applied.
-
-If you have a JSON file like:
-
----
-{
- "name": "vscode-plandex",
- "displayName": "Plandex",
- "description": "VSCode extension for Plandex integration",
- "version": "0.1.0",
- "engines": {
- "vscode": "^1.80.0"
- },
- "categories": [
- "Other"
- ],
- "activationEvents": [
- "onLanguage:plandex"
- ],
- "main": "./dist/extension.js",
- "contributes": {
- "languages": [{
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- }],
- "commands": [
- {
- "command": "plandex.tellPlandex",
- "title": "Tell Plandex"
- }
- ],
- "keybindings": [{
- "command": "plandex.showFilePicker",
- "key": "@",
- "when": "editorTextFocus && editorLangId == plandex"
- }]
- },
- "scripts": {
- "vscode:prepublish": "npm run package",
- "compile": "webpack",
- },
- "devDependencies": {
- "@types/vscode": "^1.80.0",
- "@types/glob": "^8.1.0",
- }
-}
----
-
-And you are adding a new key to the 'contributes' object, you MUST NOT output a file block like:
-
----
-
-{
- "contributes": {
- "languages": [
- {
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- "extensions": [".pd"],
- "configuration": "./language-configuration.json"
- }
- ],
- "grammars": [
- {
- "language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
- }
- ]
- }
-}
-
----
-
-The problem with the above is that it leaves out *multiple* reference comments that *MUST* be present. It is EXTREMELY IMPORTANT that you include these references.
-
-You also MUST NOT output a file block like:
-
----
-
-{
- // ... existing code ...
-
- "contributes":{
- "languages": [
- {
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- "extensions": [".pd"],
- "configuration": "./language-configuration.json"
- }
- ],
- "grammars": [
- {
- "language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
- }
- ]
- }
-}
-
----
-
-This ONLY includes a single reference comment for the code that isn't changing *before* the change. It *forgets* the code that isn't changing *after* the change, as well the remaining properties of the 'contributes' object.
-
-Here's the CORRECT way to output the file block for this change:
-
----
-
-{
- // ... existing code ...
-
- "contributes": {
- "languages": [
- {
- "id": "plandex",
- "aliases": ["Plandex", "plandex"],
- "extensions": [".pd"],
- "configuration": "./language-configuration.json"
- }
- ],
- "grammars": [
- {
- "language": "plandex",
- "scopeName": "text.plandex",
- "path": "./syntaxes/plandex.tmLanguage.json",
- "embeddedLanguages": {
- "meta.embedded.block.yaml": "yaml",
- "text.html.markdown": "markdown"
- }
- }
- ],
-
- // ... existing code ...
- },
-
- // ... existing code ...
-}
----
-
-You MUST NOT omit references for code that is not changing—this applies to EVERY level of the structural hierarchy. No matter how deep the nesting, every level MUST be accounted for with references if it includes code that is not included in the file block and is not changing.
-
-You MUST ONLY use the exact comment "// ... existing code ..." (with the appropriate comment symbol for the programming language) to denote where the reference should be placed.
-
-You MUST NOT use any other form of reference comment. ONLY use "// ... existing code ...".
-
-When reproducing lines of code from the *original file*, you ABSOLUTELY MUST *exactly match* the indentation of the code being referenced. Do NOT alter the indentation of the code being referenced in any way. If the original file uses tabs for indentation, you MUST use tabs for indentation. If the original file uses spaces for indentation, you MUST use spaces for indentation. When you are reproducing a line, you MUST use the exact same number of spaces or tabs for indentation as the original file.
-
-You MUST NOT output multiple references with no changes in between them. DO NOT UNDER ANY CIRCUMSTANCES DO THIS:
-
----
-function fooBar() error {
- log.Println("fooBar")
-
- // ... existing code ...
-
- // ... existing code ...
-
- return nil
-}
----
-
-It must instead be:
-
----
-function fooBar() error {
- log.Println("fooBar")
-
- // ... existing code ...
-
- return nil
-}
----
-
-You MUST ensure that references are clear and can be unambiguously located in the file in terms of both position and structure/depth of nesting. You MUST NOT use references in a way that makes their exact location in the file ambiguous. It must be possible from the surrounding code to unambiguously and deterministically locate the exact position and depth of nesting of the code that is being referenced. Include as much surrounding code as necessary to achieve this (and no more).
-
-For example, if the original file looks like this:
-
----
-const a = [
- 8,
- 9,
- 10,
- 11,
- 12,
- 13,
- 14,
- 15,
-]
----
-
-you MUST NOT do this:
-
----
-const a = [
- // ... existing code ...
- 1,
- 5,
- 7,
- // ... existing code ...
-]
----
-
-Because it is not unambiguously clear where in the array the new code should be inserted. It could be inserted between any pair of existing elements. The reference comment does not make it clear which, so it is ambiguous.
-
-The correct way to do it is:
-
----
-const a = [
- // ... existing code ...
- 10,
- 1,
- 5,
- 7,
- 11,
- // ... existing code ...
-]
----
-
-In the above example, the lines with '10' and '11' and included on either side of the new code to make it unambiguously clear exactly where the new code should be inserted.
-
-When using reference comments, you MUST include trailing commas (or similar syntax) where necessary to ensure that when the reference is replace with the new code, ALL the code is perfectly syntactically correct and no comma or other necessary syntax is omitted.
-
-You MUST NOT do this:
-
----
-const a = [
- 1,
- 5
- // ... existing code ...
-]
----
-
-Because it leaves out a necessary trailing comman after the '5'. Instead do this:
-
----
-const a = [
- 1,
- 5,
- // ... existing code ...
-]
----
-
-Reference comments MUST ALWAYS be on their *OWN LINES*. You MUST NEVER include a reference comment on the same line as code.
-
-You MUST NOT do this:
-
----
-const a = [1, 2, /* ... existing code ... */, 4, 5]
----
-
-Instead, rewrite the entire line to include the new code without using a reference comment:
-
----
-const a = [1, 2, 11, 15, 14, 4, 5]
----
-
-You MUST NOT extra newlines around a reference comment unless they are also present in the original file. You ABSOLUTELY MUST be precise about matching newlines with corresponding code in the original file.
-
-If the original file looks like this:
-
----
-package main
-
-import (
- "fmt"
- "os"
-)
-
-func main() {
- fmt.Println("Hello, World!")
- exec()
- measure()
- os.Exit(0)
-}
----
-
-DO NOT output superfluous newlines before or after reference comments like this:
-
----
-
-// ... existing code ...
-
-func main() {
- fmt.Println("Hello, World!")
- prepareData()
-
- // ... existing code ...
-
-}
-
----
-
-Instead, do this:
-
----
-// ... existing code ...
-
-func main() {
- fmt.Println("Hello, World!")
- prepareData()
- // ... existing code ...
-}
----
-
-Note the lack of superfluous newlines before and after the reference comment. There is a newline included between the first '// ... existing code ...' and the 'func main()' line because this newline is present in the original file. There is no newline *before* the first '// ... existing code ...' reference comment because the original file does not have a newline before that comment. Similarly, there is no newline before *or* after the second '// ... existing code ...' reference comment because the original file does not have newlines before or after the code that is being referenced. Newlines are SIGNIFICANT—you must strive to maintain consistent formatting between the original file and the changes in the file block.
-
-*
-
-If code is being removed from a file and not replaced with new code, the removal MUST ALWAYS WITHOUT EXCEPTION be shown in a labelled file block according to your instructions. Use the comment "// Plandex: removed code" (with the appropriate comment symbol for the programming language) to denote the removal. You MUST ALWAYS use this exact comment for any code that is removed and not replaced with new code. DO NOT USE ANY OTHER COMMENT FOR CODE REMOVAL.
-
-Do NOT use any other formatting apart from a labelled file block with the comment "// Plandex: removed code" to denote code removal.
-
-Example of code being removed and not replaced with new code:
-
----
-function fooBar() {
- log.Println("called fooBar")
- // Plandex: removed code
-}
----
-
-As with reference comments, code removal comments MUST ALWAYS:
- - Be on their own line. They must not be on the same line as any other code.
- - Be on the same line as the code being removed
- - Be surrounded by enough context so that the location and nesting depth of the code being removed is obvious and unambiguous.
-
-Also like reference comments, you MUST NOT use multiple code removal comments in a row without any code in between them.
-
-You MUST NOT do this:
-
----
-function fooBar() {
- // Plandex: removed code
- // Plandex: removed code
- exec()
-}
----
-
-Instead, do this:
-
----
-function fooBar() {
- // Plandex: removed code
- exec()
-}
----
-
-You MUST NOT use reference comments and removal comments together in an ambiguous way. Do NOT do this:
-
----
-function fooBar() {
- log.Println("called fooBar")
- // Plandex: removed code
- // ... existing code ...
-}
----
-
-Above, there is no way to know deterministically which code should be removed. Instead, include context that makes it clear and unambiguous which code should be removed:
-
----
-function fooBar() {
- log.Println("called fooBar")
- // Plandex: removed code
- exec()
- // ... existing code ...
-}
----
-
-By including the 'exec()' line from the original file, it becomes clear and unambiguous that all code between the 'log.Println("called fooBar")' line and the 'exec()' line is being removed.
-
-*
-
-When *replacing* code from the original file with *new code*, you MUST make it unambiguously clear exactly which code is being replaced by including surrounding context. Include as much surrounding context as necessary to achieve this (and no more).
-
-If the original file looks like this:
-
----
-class FooBar {
- func baz() {
- log.Println("baz")
- }
-
- func bar() {
- log.Println("bar")
- sendMessage("bar")
- reportSentMessage()
- }
-
- func qux() {
- log.Println("qux")
- }
-
- func axon() {
- log.Println("axon")
- escapeFromBar()
- runAway()
- }
-
- func tango() {
- log.Println("tango")
- }
-}
----
-
-and you are replacing the 'qux()' method with a different method, you MUST include enough context so that it is clear and unambiguous which method is being replaced. Do NOT do this:
-
----
-class FooBar {
- // ... existing code ...
-
- func updatedQux() {
- log.Println("updatedQux")
- }
-
- // ... existing code ...
-}
----
-
-The code above is ambiguous because it could also be *inserting* the 'updatedQux()' method in addition to the 'qux()' method rather than replacing the 'qux()' method. Instead, include enough context so that it is clear and unambiguous which method is being replaced, like this:
-
----
-class FooBar {
- // ... existing code ...
-
- func bar() {
- // ... existing code ...
- }
-
- func updatedQux() {
- log.Println("updatedQux")
- }
-
- func axon() {
- // ... existing code ...
- }
-
- // ... existing code ...
-}
----
-
-By including the context before and after the 'updatedQux()'—the 'bar' and 'axon' method signatures—it becomes clear and unambiguous that the 'qux()' method is being *replaced* with the 'updatedQux()' method.
-
-*
-
-When using an "... existing code ..." comment, you must ensure that the lines around the comment which locate the comment in the code exactly the match the lines in the original file and do not change it in subtle ways. For example, if the original file looks like this:
-
----
-{
- "key1": [{
- "subkey1": "value1",
- "subkey2": "value2"
- }],
- "key2": "value2"
-}
----
-
-DO NOT output a file block like this:
-
----
-{
- "key1": [
- // ... existing code ...
- ],
- "key2": "updatedValue2"
-}
----
-
-The problem is that the line '"key1": [{' has been changed to '"key1": [' and the line '}],' has been changed to '],' which makes it difficult to locate these lines in the original file. Instead, do this:
-
----
-{
- "key1": [{
- // ... existing code ...
- }],
- "key2": "updatedValue2"
-}
----
-
-Note that the lines around the "... existing code ..." comment exactly match the lines in the original file.
-
-*
-
-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.
-
-For example, if the original file looks like this:
-
----
-package main
-
-import "fmt"
-
-func main() {
- fmt.Println("Hello, World!")
-}
-
-func fooBar() {
- fmt.Println("fooBar")
-}
----
-
-DO NOT output a file block like this:
-
----
-func main() {
- fmt.Println("Hello, World!")
- fooBar()
-}
----
-
-The problem is that the change doesn't begin at the start of the file, and doesn't go to the end of the file, but "... existing code ..." comments are missing from both before and after the change. Instead, do this:
-
----
-// ... existing code ...
-
-func main() {
- fmt.Println("Hello, World!")
- fooBar()
-}
-
-// ... existing code ...
----
-
-Now the code before and after the change is accounted for.
-
-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.
-
-*
-
-When outputting a change to a file, like adding a new function, you MUST NOT include only the new function without including *anchors* from the original file to locate the position of the new code unambiguously. For example, if the original file looks like this:
-
----
-function someFunction() {
- console.log("someFunction")
- const res = await fetch("https://example.com")
- processResponse(res)
- return res
-}
-
-function processResponse(res) {
- console.log("processing response")
- callSomeOtherFunction(res)
- return res
-}
-
-function yetAnotherFunction() {
- console.log("yetAnotherFunction")
-}
-
-function callSomething() {
- console.log("callSomething")
- await logSomething()
- return "something"
-}
----
-
-DO NOT output a file block like this:
-
----
-// ... existing code ...
-
-function newFunction() {
- console.log("newFunction")
- const res = await callSomething()
- return res
-}
-
-// ... existing code ...
----
-
-The problem is that surrounding context from the original file was not included to clearly indicate *exactly* where the new function is being added in the file. Instead, do this:
-
----
-// ... existing code ...
-
-function processResponse(res) {
- // ... existing code ...
-}
-
-function newFunction() {
- console.log("newFunction")
- const res = await callSomething()
- return res
-}
-
-// ... existing code ...
----
-
-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.
-
-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.
-
-*
-
-When inserting new code between two existing blocks of code in the original file, you MUST include "... existing code ..." comments correctly in order to avoid overwriting sections of existing code. For example, if the original file looks like this:
-
----
-
-func main() {
- console.log("main")
-}
-
-func fooBar() {
- console.log("fooBar")
-}
-
-func baz() {
- console.log("baz")
-}
-
-func qux() {
- console.log("qux")
-}
-
-func quix() {
- console.log("quix")
-}
-
-func qwoo() {
- console.log("qwoo")
-}
-
-func last() {
- console.log("last")
-}
-
----
-
-DO NOT output a file block like this to demonstrate that new code will be inserted somewhere between the 'fooBar' and 'last' functions:
-
----
-// ... existing code ...
-
-func fooBar() {
- console.log("fooBar")
-}
-
-func newCode() {
- console.log("newCode")
-}
-
-func last() {
- console.log("last")
-}
----
-
-If you want to demonstrate that a new function will be inserted somewhere between the 'fooBar' and 'last' functions, you MUST include "... existing code ..." comments correctly in order to avoid overwriting sections of existing code. Instead, do this to show exactly where the new function will be inserted:
-
----
-
-// ... existing code ...
-
-func baz() {
- // ... existing code ...
-}
-
-func newCode() {
- console.log("newCode")
-}
-
-func qux() {
- // ... existing code ...
-}
-
-// ... existing code ...
-
-
-Or this to show that the new function will be inserted *somehwere* between the 'fooBar' and 'last' functions:
-
----
-
-// ... existing code ...
-
-func fooBar() {
- console.log("fooBar")
-}
-
-// ... existing code ...
-
-func newCode() {
- console.log("newCode")
-}
-
-// ... existing code ...
-
-func last() {
- console.log("last")
-}
-
----
-
-Either way, you MUST NOT leave out the "... existing code ..." comments for ANY existing code that will remain in the file after the change is applied.
-
-*
-
-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 the original file is:
-
----
-func buck() {
- console.log("buck")
-}
-
-func qux() {
- console.log("qux")
-}
-
-func fooBar() {
- console.log("fooBar")
-}
-
-func baz() {
- console.log("baz")
-}
-
-func yup() {
- console.log("yup")
-}
----
-
-DO NOT output a file block like this to demonstrate that new code will be inserted between the 'fooBar' and 'baz' functions:
-
----
-// ... existing code ...
-
-func baz() {
- console.log("baz-updated")
-}
-
-// ... existing code ...
-
-func qux() {
- console.log("qux-updated")
-}
-
-// ... existing code ...
-
----
-
-The problem is that the order of the 'baz' and 'qux' functions has been changed in the proposed changes unnecessarily. Instead, do this:
-
----
-// ... existing code ...
-
-func qux() {
- console.log("qux-updated")
-}
-
-// ... existing code ...
-
-func baz() {
- console.log("baz-updated")
-}
-
-// ... existing code ...
----
-
-Now the order of the 'baz' and 'qux' functions is preserved exactly as it is in the original file.
-
-*
-
-Here are some important examples of INCORRECT vs CORRECT file updates:
-
-Example 1 - Adding a new route:
-
-❌ INCORRECT - Replacing instead of inserting:
-` + "```go" + `
-// ... existing code ...
-
-r.HandleFunc(prefix+"/api/users", handlers.ListUsersHandler).Methods("GET")
-
-r.HandleFunc(prefix+"/api/config", handlers.GetConfigHandler).Methods("GET")
-
-// ... existing code ...
-` + "```" + `
-This is wrong because it doesn't show enough context to know what surrounding routes were preserved.
-
-✅ CORRECT - Proper insertion with context:
-` + "```go" + `
-// ... existing code ...
-
-r.HandleFunc(prefix+"/api/users", handlers.ListUsersHandler).Methods("GET")
-r.HandleFunc(prefix+"/api/teams", handlers.ListTeamsHandler).Methods("GET")
-
-r.HandleFunc(prefix+"/api/config", handlers.GetConfigHandler).Methods("GET")
-
-r.HandleFunc(prefix+"/api/settings", handlers.GetSettingsHandler).Methods("GET")
-r.HandleFunc(prefix+"/api/status", handlers.GetStatusHandler).Methods("GET")
-
-// ... existing code ...
-` + "```" + `
-
-Example 2 - Adding a method to a class:
-
-❌ INCORRECT - Ambiguous insertion:
-` + "```go" + `
-class UserService {
- // ... existing code ...
-
- async createUser(data) {
- // new method
- }
-
- // ... existing code ...
-}
-` + "```" + `
-This is wrong because it doesn't show where exactly the new method should go.
-
-✅ CORRECT - Clear insertion point:
-` + "```go" + `
-class UserService {
- // ... existing code ...
-
- async getUser(id) {
- return await this.db.users.findOne(id)
- }
-
- async createUser(data) {
- return await this.db.users.create(data)
- }
-
- async updateUser(id, data) {
- return await this.db.users.update(id, data)
- }
-
- // ... existing code ...
-}
-` + "```" + `
-
-Example 3 - Adding a configuration section:
-
-❌ INCORRECT - Lost context:
-` + "```json" + `
-{
- "database": {
- "host": "localhost",
- "port": 5432
- },
- "newFeature": {
- "enabled": true,
- "timeout": 30
- }
-}
-` + "```" + `
-This is wrong because it dropped existing configuration sections.
-
-✅ CORRECT - Preserved context:
-` + "```json" + `
-{
- // ... existing code ...
-
- "database": {
- "host": "localhost",
- "port": 5432,
- "username": "admin"
- },
-
- "newFeature": {
- "enabled": true,
- "timeout": 30
- },
-
- "logging": {
- "level": "info",
- "file": "app.log"
- }
-
- // ... existing code ...
-}
-` + "```" + `
-
-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
-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:
-
----
-**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]'
-- 'prepend [new code description] to the start of the file, immediately before [specific code or structure in original file]'
-- 'append [new code description] to the end of the file, immediately after [specific code or structure in original file]'
-- 'overwrite the entire file with [new code description]'
-- 'replace code between [specific code or structure in original file] and the immediately adjacent [specific *adjacent* code or structure in original file] with [new code description]'
-- 'replace [specific code or structure in original file] with [new code description]'
-- '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!
-
-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.
-
-When inserting or replacing code, the "specific code or structure" or "specific *adjacent* code or structure" must be the code or structure that is *immediately before* and *immediately after* the point where the new code will be inserted. These two code structures ABSOLUTELY MUST be *adjacent* in the original file. DO NOT insert code between two code structures that aren't *immediately adjacent* in the original file. You must be precise in pinpointing the exact location of the change.
-
-Do NOT leave off any part of the explanation as described above. Do NOT output something like: 'I'll add the doRequest method to the class' or 'I'll add the types for making the api call'. These do NOT exactly match one of the above formats. Instead, you MUST output the full explanation as described above like:
-
-- **Updating ` + "`server/api/client.go`**" + `: I'll add the ` + "`doRequest`" + ` method between the constructor method and the ` + "`getUser`" + ` method.
-- **Updating ` + "`server/types/api.go`**" + `: I'll add the types for making the api call between the imports and the ` + "`init`" + ` method.
-- **Updating ` + "`cli/cmd/update.go`**" + `: I'll overwrite the entire file with new code for the ` + "`update`" + ` CLI command.
-- **Updating ` + "`server/db/user.go`**" + `: I'll add the ` + "`update`" + ` function between the ` + "`get`" + ` and the end of the file.
-- **Updating ` + "`server/db/user.go`**" + `: I'll append a new ` + "`update`" + ` function to the end of the file.
-- **Updating ` + "`server/db/user.go`**" + `: I'll prepend a new ` + "`update`" + ` function to the start of the file.
-- **Updating ` + "`server/db/user.go`**" + `: I'll add a new ` + "`update`" + ` function immediately after the ` + "`get`" + ` method.
-- **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.
-
-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 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:
-
----
-package something
-
-type T struct {}
-
-func Add(t *T) {
- t.doSomething()
- t.doSomethingElse()
- t.doSomethingElseAgain()
- t.doSomethingOnceMore()
-}
----
-
-DO NOT output an explanation like this:
-
----
-**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call between the 'doSomethingElse' method and the 'doSomethingOnceMore' method.
----
-
-The problem is the 'doSomethingElse' function call and the 'doSomethingOnceMore' method are not *immediately adjacent* in the original file. Instead, output an explanation like this:
-
----
-**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call between the 'doSomethingElse' method and the 'doSomethingElseAgain' method.
----
-
-The 'doSomethingElse' method and the 'doSomethingElseAgain' method are *immediately adjacent* in the original file, so the explanation is correct.
-
-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.
-
-Example:
-
----
-**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call immediately after the 'doSomethingElse' method.
-
-- server/something/something.go:
-` + "```" + `
-// ... existing code ...
-
-func Add(t *T) {
- // ... existing code ...
- doSomethingElse()
- anotherThing()
- doSomethingElseAgain()
- // ... existing code ...
-}
-` + "```" + `
-
-*
-
-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].
-
-*
-
-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 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.
-
-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.
-
-If a file must begin with an "... existing code ..." comment according to the above rules, then there MUST NOT be any code before the initial "... existing code ..." comment.
-
-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:
-
----
-// ... existing code ...
-
-func (a *Api) NewMethod() {
- callExistingMethod()
-}
-
-func (a *Api) LoadContext(planId, branch string, req
- shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {
- // ... existing code ...
-}
----
-
-is NOT CORRECT, because the last line is not an "... existing code ..." comment—it is rather the '}' closing bracket of the function. Instead, it must be:
-
----
-// ... existing code ...
-
-func (a *Api) NewMethod() {
- callExistingMethod()
-}
-
-func (a *Api) LoadContext(planId, branch string, req
- shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {
- // ... existing code ...
-}
-
-// ... existing code ...
----
-
-Now the final line is an "... existing code ..." comment, which is correct.
-`
-
-const PendingScriptPrompt = `
- ## _pending.sh file
-
- You can write to a *special path*: ` + "_pending.sh" + `
-
- This file allows you to execute commands in the context of the *files in context* and the *pending files* (the files that will be created or updated by the plan). This script will be executed on the *Plandex server*, not on the user's machine. You can ONLY use this file to manipulate files that are in context or *pending*. You cannot use this file to execute commands outside the context of the plan or files with pending updates.
-
- The ` + "_pending.sh" + ` can take the following actions and use the following special commands:
-
- - Move or rename a file, directory, or pattern of files that are in context or pending with the special` + "`move`" + ` command (it works just like the 'mv' command and takes arguments in the same way):
- - move 'components/page.tsx' 'pages/page.tsx'
- - move 'pages/' 'components/'
- - move 'components/*.page.ts' 'pages/'
- - Copy a file, directory, or pattern of files that are in context or pending with the special ` + "`copy`" + ` command (it works just like the 'cp' command and takes arguments in the same way):
- - copy 'components/page.tsx' 'pages/page.tsx'
- - copy 'pages/' 'components/'
- - copy 'components/*.page.ts' 'pages/'
- - Clear any pending changes to files, directories, or patterns of files that are in context or pending with the special` + "`reject`" + ` command (it works just like the 'git reset --hard' command and takes arguments in the same way):
- - reject 'pages/page.tsx'
- - reject 'components/'
- - reject 'components/*.page.ts'
- - Remove a file, directory, or pattern of files that are in context or pending with the ` + "`remove`" + ` command (it works just like the 'rm -rf' command and takes arguments in the same way):
- - remove 'pages/'
- - remove 'components/page.tsx'
- - remove 'components/*.page.ts'
-
- You CANNOT AND MUST NOT use *any other commands* in the _pending.sh script. Only the commands listed above are allowed. All the above commands (move, reject, remove) will be available to you when the script is executed. Again, NO OTHER commands are allowed or available to you—**this is absolutely critical.**
-
- You MUST NOT create directories in the _pending.sh script. They will be created as needed by the special commands.
-
- You MUST NOT include comments in the _pending.sh script. There MUST NOT be *anything* at all apart from the special commands and their arguments.
-
- Do NOT use 'mv', 'cp', or 'rm' commands in the _pending.sh script. Use the special commands (` + "`move`" + `, ` + "`copy`" + `, ` + "`reject`" + `, ` + "`remove`" + `) instead.
-
- The _pending.sh script is executed at the *root directory* that contains all context files and pending files. You can only reference files and directories that are listed in context or in the pending files.
-
- Each _pending.sh script file block is *independent*. It will be executed independently of any others. You can output multiple _pending.sh scripts in the same response if needed. _pending.sh scripts are *not* persisted. Each one is executed once at the end of the response and then discarded. You must treat each _pending.sh block as if you are *creating a new file* which is independent of any other files.
-
- Do NOT include the` + "`#!/bin/bash`" + ` line at the top of a _pending.sh script. Every _pending.sh script will be executed with ` + "`#!/bin/bash`" + ` already included.
-
- You also must not include error handling or logging in a _pending.sh script. This will be handled outside the script.
-
- Wrap paths in single quotes when using the move, reject, or remove commands.
-
- You do not need to give _pending.sh scripts execution privileges or any other permissions. This is handled outside the script.
-
- Example:
-
- - _pending.sh:
- ` + "```bash" + `
- move 'components/page.tsx' 'pages/page.tsx'
- ` + "```" + `
-
- You ABSOLUTEY MUST use the _pending.sh script when moving, renaming, copying, rejecting, or removing files or directories that are in context or pending. Do NOT UNDER ANY CIRCUMSTANCES use a file block to do any of these actions; ALWAYS use the _pending.sh script instead.
-
- If the user asks you to move or change the path of a file that is in context or pending, you MUST use the _pending.sh script with a 'move' command to do this. Do NOT use a file block to do this.
-
- If the user asks you to copy a file that is in context or pending, you MUST use the _pending.sh script with a 'copy' command to do this. Do NOT use a file block to do this.
-
- If the user asks you to revert all the changes you've made to a file that is in context or pending, you MUST use the _pending.sh script with a 'reject' command to do this. Do NOT use a file block to do this.
-
- If the user asks you to remove a file that is in context or pending, you MUST use the _pending.sh script with a 'remove' command to do this. Do NOT use a file block to do this.
-`
-
-const ApplyScriptPrompt = `
-## _apply.sh file and command execution
-
-**Execution mode is enabled.**
-
-In addition to creating and updating files, you can also execute commands on the user's machine by writing to a another *special path*: ` + "_apply.sh" + `
-
-This file allows you to execute commands in the context of the *user's machine*, not the Plandex server, when the user applies the changes from the plan to their project. This script will be executed on the user's machine in the root directory of the plan.
-
-Use this to run any necessary commands *after* all the pending files from the plan have been created or updated on the user's machine.
-
-DO NOT use the _apply.sh script to move, copy, reject, or remove files that are in the context of the plan or the pending files—use the _pending.sh script for those actions.
-
-DO NOT use the _apply.sh script to create directory paths for files that are in context or pending. Any required directories will be created automatically when the plan is applied.
-
-Use the appropriate commands for the user's operating system and shell, which will be supplied to you in the prompt.
-
-When using third party tools, do not assume the user has them installed. The _apply.sh script should always first check if the tool is installed. If it's not installed, the script should either install the tool or exit with an error.
-
-When determining whether to install a tool or exit with an error if a necessary tool or dependency is missing, you can make some assumptions about what is likely installed based on the user's operating system, the files and paths in the context of the plan, and the conversation history.
-
-The _apply.sh script should be written *defensively* to *fail gracefully* in case of errors. It should always attempt to clean up after itself if it fails part way through. As much as possible, it should be *idempotent*.
-
-Unless the user has specifically directed you otherwise, the _apply.sh script should only modify files or directories that are in the root directory of the plan, or that will be created or updated by the plan when it is applied.
-
-In general, the _apply.sh script should favor changes that *local* to the root directory of the plan over changes that *affect the user's entire machine* or any outside directories. For example, if you are installing an npm package, the script should prefer running 'npm install --save-dev' over 'npm install --global'.
-
-You can include logging for key steps in the _apply.sh script but don't overdo it. Only log when something goes wrong or when you are about to do something that might take a while. Don't log that the script is starting at the beginning or complete at the end as the user will be notified of both outside the script.
-
-Include comments for key sections in the _apply.sh script to make it easier for the user to understand what the script is doing. But again, don't overdo it.
-
-BE CAREFUL AND CONSERVATIVE WHEN MAKING CHANGES TO THE USER'S MACHINE. Only make changes that are necessary in the context of the plan. Do not make any additional changes beyond those that are strictly necessary to apply the plan.
-
-If a command is risky in terms of potentially harming the user's system, or it has security implications, tell the user to take these actions themselves after the plan is applied. Do NOT include such commands in the _apply.sh script. Apart from risky or dangerous commands, or commands that aren't strictly necessary to apply the plan, you should include *all* commands to be run in the _apply.sh script. Do NOT give the user commands to run themselves after the plan is applied, *unless* they are risky or dangerous or optional and not strictly necessary to apply the plan; instead, the commands that are safe to run and are strictly necessary to apply the plan in the _apply.sh script.
-
-Unless some required commands are potentially risky or dangerous, you MUST include *all* commands needed to implement the plan in the _apply.sh script. Do NOT leave out any commands or leave commands for the user to run themselves after the plan is applied——include them all in the _apply.sh script.
-
-DO NOT give the user any additional commands to run—include them all in the _apply.sh script. For example, if you have created or updated a Makefile, you must include the 'make' command in the _apply.sh script instead of telling the user to run 'make' after the plan is applied. Similarly, if you have created or updated a package.json file, you must include the 'npm install' command in the _apply.sh script instead of telling the user to run 'npm install' after the plan is applied. If you have written or updated tests, you must include the command to run the tests in the _apply.sh script instead of telling the user to run the tests after the plan is applied.
-
-If appropriate, also include a command to run the actual program in _apply.sh. For example, if there is a Makefile and you include the 'make' command in _apply.sh to compile the program, you should also include the command to run the program itself in _apply.sh. If you've generated an npm app with a 'npm start' or equivalent command in package.json, you should also include that command in _apply.sh to start the application. Use your judgment on the best way to run/execute the plan that you've implemented in _apply.sh—but do run it if you can.
-
-When running commands in _apply.sh, DO NOT hide or filter the output of the commands in any way. For example, do not do something like this:
-
-` + "```bash" + `
-if ! make clean && make; then
- echo "Error: Compilation failed"
- exit 1
-fi
-` + "```" + `
-
-because the output of the 'make clean' and 'make' commands won't be shown to the user. Instead, run each command separately and show the output:
-
-` + "```bash" + `
-make clean
-make
-` + "```" + `
-
-The _apply.sh script can be *updated* over the course of the plan. Unlike the _pending.sh script which runs each block independently, there is just a *single* _apply.sh script that is created and then updated as needed during the plan. It must be maintained in a safe state that is *ready to be executed* when the plan is applied.
-
-If you've already generated a _apply.sh script during the plan and need to add additional commands, you MUST *update* the existing _apply.sh with new commands. Do NOT overwrite the existing _apply.sh unless it is necessary to implement the plan. As with other file blocks that are updating an existing file, use the appropriate "... existing code ..." comments to avoid overwriting any existing code in the _apply.sh script.
-
-Do NOT use the _apply.sh script to move, copy, reject, or remove files that are in the context of the plan or the pending files—use the _pending.sh script for those actions.
-
-If the plan includes other script files, apart from _apply.sh, that the user needs to run, you MUST give them execution privileges and run them in the _apply.sh script. Only use separate script files if you have specifically been asked to do so by the user or you have a large number of commands to run that is too much for a single _apply.sh script. Otherwise, you MUST include *all* commands to be run in the _apply.sh script, and not use separate script files.
-
-Running the _apply.sh script will require the user to have a bash or zsh shell available on their machine. You can assume that the user has bash or zsh installed. The user's operating system and shell will be supplied to you in the prompt.
-
-You MUST NOT include the shebang line ` + "(`#!/bin/bash` or `#!/bin/zsh`)" + ` line at the top of the _apply.sh script. Every _apply.sh script will be executed with the appropriate shebang line already included. DO NOT include the shebang line in the _apply.sh script.
-
-Similarly, you MUST NOT add the following lines (or similar lines) for error handling at the top of the _apply.sh script:
-
-` + "```bash" + `
-set -euo pipefail
-trap 'echo "Error on line $LINENO: $BASH_COMMAND"' ERR
-` + "```" + `
-
-The _apply.sh script will be executed with the above error handling already included.
-
-You DO NOT need to give the _apply.sh script execution privileges or any other permissions. This is handled outside the script.
-
-You ABSOLUTELY MUST NOT tell the user to run the _apply.sh script or that you are waiting for them to run it. It will be run automatically when the user applies the plan.
-
-You MUST NOT tell the user to do anything themselves that's included in the _apply.sh script. It will be run automatically when the user applies the plan.
-
-Example, creating initial _apply.sh:
-
-- _apply.sh:
-` + "```bash" + `
-# Check for node/npm
-if ! command -v node > /dev/null; then
- echo "Error: node is not installed"
- exit 1
-fi
-
-if ! command -v npm > /dev/null; then
- echo "Error: npm is not installed"
- exit 1
-fi
-
-# Install dependencies
-echo "Installing project dependencies..."
-npm install --save-dev \
- "@types/react@^18.0.0" \
- "typescript@^4.9.0" \
- "prettier@^2.8.0"
-
-# Generate tsconfig if it doesn't exist
-if [ ! -f "tsconfig.json" ]; then
- echo "Generating TypeScript configuration..."
- npx tsc --init --jsx react
-fi
-` + "```" + `
-
-Example, updating _apply.sh:
-
-- _apply.sh:
-` + "```bash" + `
-# ... existing code ...
-
-# Install dependencies
-echo "Installing project dependencies..."
-npm install --save-dev \
- "@types/react@^18.0.0" \
- "typescript@^4.9.0" \
- "prettier@^2.8.0" \
- "eslint@^9.0.0" \
- "jest@^29.0.0"
-
-# ... existing code ...
-` + "```" + `
-`
-
-var ApplyScriptPromptNumTokens int
-
-const ApplyScriptPromptSummary = `
-Write any commands that need to be run after the plan is applied to the special _apply.sh file.
-
-Key instructions for _apply.sh:
-
-- The script runs on the user's machine after plan files are created/updated
-- DO NOT use it for file operations (move/copy/reject/remove) - use _pending.sh instead
-- Include ALL necessary commands unless they are risky/dangerous
-- Prefer local changes over global system changes
-- Check for required tools before using them
-- Can be updated during the plan but must always be in executable state
-- Should be idempotent and fail gracefully when possible
-- DO NOT hide or filter the output of commands—output of all commands must be shown to the user
-- DO NOT UNDER ANY CIRCUMSTANCES:
- - Add shebang or error handling (handled externally)
- - Give the _apply.sh script execution privileges or any other permissions (handled externally)
- - Create directories for plan files
-- The script runs automatically - never tell users to run it themselves
-- Include all safe and necessary commands in the script rather than telling users to run them later
-- Include *all* commands to build/compile/install/run the program when appropriate
-- If you've already generated a _apply.sh script during the plan, do not overwrite it unless it is necessary to implement the plan. Instead, update the existing _apply.sh with additional commands. Use the "... existing code ..." comments to avoid overwriting any existing code in the _apply.sh script when updating it, just as you would when updating any other file.
-`
-
-var ApplyScriptSummaryNumTokens int
-
-var NoApplyScriptPrompt = `
-
-## No execution of commands
-
-**Execution mode is disabled.**
-
-You cannot execute any commands in the context of the pla- You can only create and update files. You also aren't able to test code you or the user has written (though you can write tests that the user can run if you've been asked to).
-
-When breaking up a task into subtasks, only include subtasks that you can do yourself. If a subtask requires executing code or commands, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that you can complete by creating or updating files.
-
-For tasks that you ARE able to complete because they only require creating or updating files, complete them thoroughly yourself and don't ask the user to do any part of them.
-
-You MUST consider the plan complete if the only remaining tasks must be completed by the user. Explicitly state when this is the case.
-`
-
-var NoApplyScriptPromptNumTokens int
-
-// Not using currently, considering for use in smarter context loader in the future (load just what a subtask needs)
-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`." + `
-
-Example:
-
-### Subtasks
-
-1. Add the necessary code to the 'game_logic.h' file to define the 'updateGameLogic' function
-Uses: ` + "`src/game_logic.h`" + `
-
-2. Add the necessary code to the 'game_logic.c' file to implement the 'updateGameLogic' function
-Uses: ` + "`src/game_logic.c`" + `
-
-3. Update the 'main.c' file to call the 'updateGameLogic' function
-Uses: ` + "`src/main.c`" + `
-
-Be exhaustive in the 'Uses:' list. Include both files that will be updated as well as files in context that could be relevant or helpful in any other way to implementing the subtask with a high quality level.
-
-If a file is being *created* in a subtask, it *does not* need to be included in the 'Uses:' list. Only include files that will be *updated* in the subtask.
-`
-
-var UsesPromptNumTokens int
-
-const ContextLoadingRules = `When loading context, you MUST follow these rules:
-
-1. Interface & Implementation Rule:
- - When loading an implementation file, you MUST also load its interface file
- - When loading a type file, you MUST also load related type definitions
- Example: If loading 'handlers/users.go', you must also load 'types/user.go'
-
-2. Reference Implementation Rule:
- - When implementing a feature similar to an existing one, you MUST load the existing feature's files as reference
- - Look for files with similar patterns, names, or purposes
- Example: If adding user settings, load existing settings-related files
-
-3. Command Chain Rule:
- - When adding/modifying CLI commands, you MUST load:
- * The root command file (root.go)
- * Similar existing command files
- * Any parent command files
- Example: If adding 'config set', load root.go and similar 'set' commands
-
-4. API Client Chain Rule:
- - When working with API clients, you MUST load:
- * The API interface file
- * The client implementation file
- * The client setup file
- * Related error handling files
- Example: If updating API methods, load both types/api.go and api/methods.go
-
-5. Database Chain Rule:
- - When working with database operations, you MUST load:
- * Related model files
- * Related helper files
- * Similar existing DB operations
- Example: If adding user settings table, load other settings-related DB files
-
-6. Utility Dependencies Rule:
- - Examine the code you're writing for any utility function calls
- - Load ALL files containing utilities you might need
- Example: If using string formatting utilities, load the utils file
-
-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:
-
-1. Look for naming patterns:
- - Files with similar prefixes or suffixes
- - Files in similar locations
- Example: If working on 'user_config.go', look for other '*_config.go' files
-
-2. Look for feature groupings:
- - Find all files related to similar features
- - Look for files that work together
- Example: If adding settings, find all existing settings-related files
-
-3. Follow file relationships:
- - For each file you identify, check for:
- * Its interface file
- * Its test file
- * Its helper files
- * 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:
-
-1. ALL interface files for any implementations
-2. ALL type definitions needed
-3. ALL similar feature files for reference
-4. ALL utility files that might be needed
-5. ALL parent/child relationship files (like command hierarchies)
-
-You MUST explicitly state if you're missing any of these categories and load additional context if needed.`
-
-const ContextVerificationSteps = `After thinking through the initial set of files to load, you MUST verify:
-
-1. Interface Coverage:
- - For each implementation in use, are relevant types or interfaces also loaded?
- - For each type or interface in use, is its definition loaded?
-
-2. Reference Coverage:
- - For similar features, have all reference files been loaded?
- - Are you missing any patterns to follow?
-
-3. Dependency Coverage:
- - For each function/method call, is its definition loaded?
- - For each type usage, is its definition loaded?
-
-4. Command Coverage:
- - For CLI changes, is the command hierarchy loaded?
- - Are similar command patterns loaded?
-
-If any of these are "no", you MUST note additional context to load.
-
-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`" + ` ".
-
-You only need to include each of the above points in the '### Additional Context' section if they're relevant. Use your own words and your best judgement to think through which additional files may be helpful to completing this task or answering the user's question with a high level of thoroughness and quality.
-
-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.
-`
diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.go
index bbeb1c66..54a5c1f9 100644
--- a/app/server/model/prompts/exec_status.go
+++ b/app/server/model/prompts/exec_status.go
@@ -7,66 +7,37 @@ import (
const SysExecStatusShouldContinue = `You are tasked with evaluating a response generated by another AI (AI 1).
-Your goal is to determine whether the plan created by AI 1 should automatically continue or if it is considered complete. To do this, you need to analyze the latest message of the plan from AI 1 carefully and decide based on the following criteria:
+Your goal is to determine two things:
+1. Whether the current subtask was fully implemented in the message
+2. Whether the plan can automatically continue or needs user input/action
-Assess whether the user has given the AI a task to do or whether the user is just chatting with the AI. If the user is just chatting, the plan should not continue. If the AI is not clearly working on a task in its response, the plan should not continue.
+To do this, you need to analyze the latest message from AI 1 carefully and decide based on the following criteria:
-You might be supplied with a summary of the plan if one is available. If the summary is available, it will include a list of tasks to be done in the plan and whether each one has been implemented in code yet or not. If the summary is available and all tasks have been completed, the plan should not continue. If the summary is available and there are still tasks to be done, the plan should continue *unless* *all* the remaining unfinished tasks have been *fully* implemented in the latest message from AI 1. If between the latest summary and the latest message from AI 1 all tasks have been fully implemented, the plan should not continue.
+First, assess whether the current subtask was fully implemented in the message. A subtask is only considered fully implemented if all necessary code changes for that subtask have been completed with no remaining todo placeholders or partial implementations.
-If a summary is not available, the message from AI 1 that came prior to the user's prompt might also be provided. If it is provided, consider it when determining whether the plan should continue or is complete.
+Then, assess whether AI 1 has concluded with any statement that indicates either:
+- The user needs to take specific actions before the plan can proceed
+- The plan can't automatically continue for any other reason
-If any new subtasks have been added to plan that haven't been implemented yet, either in the latest summary, the latest message from AI 1, or the previous message from AI 1, the plan should continue.
+You *must* call the shouldAutoContinue function with a JSON object containing the keys 'reasoning', 'subtaskFinished', and 'shouldContinue'.
-If A1 1 has indicated that the plan is complete, but there are still subtasks remaining that have not been implemented, the plan should continue despite AI 1's statement that the plan is complete. The plan should only be considered complete if all tasks and subtasks have been fully implemented.
+Set 'reasoning' to a string briefly and succinctly explaining:
+1. Whether the current subtask was or was not fully implemented, and why
+2. Whether AI 1 indicated that user action/input is needed
-If AI 1 mentions that it has verified the plan's diffs, and either that there were no problems to fix or that it fixed all the problems, the plan must *NOT* continue, regardless of any other criteria. If AI 1 mentions that it has verified the plan's diffs, but there are still problems remaining to be fixed, the plan should continue.
+The 'subtaskFinished' key is a boolean that indicates whether the current subtask has been fully implemented in the latest message from AI 1. If the current subtask has been fully implemented, 'subtaskFinished' must be true. If the current subtask has not been fully implemented or there are unexplained todo placeholders, 'subtaskFinished' must be false. If the subtask has been skipped because it is not necessary or was already implemented in an earlier step, 'subtaskFinished' must be true.
-DO NOT only go by the latest summary when considering whether subtasks are complete. You MUST also consider the latest message from AI 1 and the previous message from AI 1 if it is provided. If the latest or previous message from AI 1 has new subtasks that have not been implemented, the plan should continue. If the latest or previous message from AI 1 has *finished* subtasks that are not marked as implemented in the summary, you MUST consider them as implemented.
-
-If no subtasks are remaining to be implemented:
- - Assess whether AI 1 has concluded with a statement that indicates either the user needs to take specific actions before the plan can proceed, or that the plan can't automatically continue for any other reason. If so, the plan should not continue.
-
-You *must* call the shouldAutoContinue function with a JSON object containing the keys 'messageSubtasksFinished', 'comments', 'reasoning', and 'shouldContinue'.
-
-The 'messageSubtasksFinished' key is an array of strings that represent subtasks that have been completed in the latest message OR the previous message (if included) from AI 1. If there are no subtasks that have been completed in the latest message, 'messageSubtasksFinished' must be an empty array. These MUST ONLY be subtasks that AI one has clearly stated are finished or done or implemented in either the latest or previous message. Do NOT list any subtasks from the summary in 'messageSubtasksFinished'. If there are no subtasks that have been completed in the latest message, 'messageSubtasksFinished' must be an empty array.
-
-The 'comments' key is an array of objects with two properties: 'txt' and 'isTodoPlaceholder'. 'txt' is the exact text of a code comment. 'isTodoPlaceholder' is a boolean that indicates whether the comment is a placeholder for a task that has not yet been implemented. This includes comments like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish implementation" or any similar placeholder comments that describe tasks that still remain to be implemented. A todo placeholder does NOT have to exactly match any of the previous examples. Use your judgment to determine whether a comment is a todo placeholder.
-
-In 'comments', you must list EVERY comment included in any code blocks within AI 1's latest response. Only list *code comments* that are valid comments for the programming language being used. Do not list logging statements or any other non-comment text that is not a valid code comment. If are no code blocks in AI 1's response or there are no comments within code blocks, 'comments' must be an empty array.
-
-If any of the comments in the 'comments' array are todo placeholders, the plan MUST continue.
-
-Set 'reasoning' to a string briefly and succinctly explaining your reasoning for why the plan should or should not continue, based on your instructions above.
-
-Take into account both the latest message from AI 1, the previous message from AI 1 if it is provided, and the latest summary if it is provided. If a subtask is marked as completed in *either* the summary, the latest message, or the previous message from AI 1, it should be considered as implemented.
-
-Between all of these sources, explain whether all subtasks have been implemented or whether there are still subtasks remaining that have not yet been completed.
-
-If there are any todo placeholders in the 'comments' array, list them ALL in 'reasoning'.
-
-If all the steps remaining are for the *user* to complete, you MUST state that the plan is complete in 'reasoning'. AI 1 can only create or update files. It cannot execute commands, run tests, or do anything else that requires user action. The task must only continue if there are still steps remaining that aren't yet completed and that AI 1 can do.
-
-If the plan should continue, you MUST state what the immediate next step should be in 'reasoning'. You MUST NOT state any subtasks that have been marked implemented in the summary or completed in the latest message or previous message from AI 1. You MUST only state what the next unimplemented subtask is and that should be done next. Subtasks MUST ALWAYS be completed in order. If subtask 3 was just completed in the latest message, and subtask 4 is the next unimplemented subtask in numerical order, you MUST state that subtask 4 should be done next. You MUST NOT skip any subtasks. You MUST NOT repeat any subtasks that have already been completed, either in the summary or in the latest or previous message from AI 1. If there is no immediate next subtask, you MUST state that the plan is complete.
-
-Set 'shouldContinue' to true if the plan should automatically continue based on your instructions above, or false otherwise.
-
-If any of the comments in the 'comments' array are todo placeholders, 'shouldContinue' must be true.
+Set 'shouldContinue' to false only if AI 1 explicitly states that user action/input is needed before continuing. In all other cases, including when there are unexplained todo placeholders, 'shouldContinue' must be true.
You must always call 'shouldAutoContinue'. Don't call any other function.`
-func GetExecStatusShouldContinue(summary, prevAssistantMsg, userPrompt, message string) string {
+func GetExecStatusShouldContinue(userPrompt, message string) string {
s := SysExecStatusShouldContinue
- if summary != "" {
- s += "\n\n**Here is the latest summary of the plan:**\n" + summary
- } else if prevAssistantMsg != "" {
- s += "\n\n**Here is the previous message AI 1:**\n" + prevAssistantMsg
- }
-
if userPrompt != "" {
s += "\n\n**Here is the user's prompt:**\n" + userPrompt
}
- s += "\n\n**Here is the latest message of the plan from AI 1:**\n" + message
+ s += "\n\n**Here is the latest message from AI 1:**\n" + message
return s
}
@@ -75,34 +46,16 @@ var ShouldAutoContinueFn = openai.FunctionDefinition{
Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
- "messageFinishedSubtasks": {
- Type: jsonschema.Array,
- Items: &jsonschema.Definition{
- Type: jsonschema.String,
- },
- },
- "comments": {
- Type: jsonschema.Array,
- Items: &jsonschema.Definition{
- Type: jsonschema.Object,
- Properties: map[string]jsonschema.Definition{
- "txt": {
- Type: jsonschema.String,
- },
- "isTodoPlaceholder": {
- Type: jsonschema.Boolean,
- },
- },
- Required: []string{"txt", "isTodoPlaceholder"},
- },
- },
"reasoning": {
Type: jsonschema.String,
},
+ "subtaskFinished": {
+ Type: jsonschema.Boolean,
+ },
"shouldContinue": {
Type: jsonschema.Boolean,
},
},
- Required: []string{"comments", "reasoning", "shouldContinue"},
+ Required: []string{"reasoning", "subtaskFinished", "shouldContinue"},
},
}
diff --git a/app/server/model/prompts/implement.go b/app/server/model/prompts/implement.go
new file mode 100644
index 00000000..d7b7d317
--- /dev/null
+++ b/app/server/model/prompts/implement.go
@@ -0,0 +1,121 @@
+package prompts
+
+func GetImplementationPrompt(subtask string) string {
+ var prompt string
+
+ prompt += `CURRENT SUBTASK:\n\n` + subtask + `\n\n` + `
+
+ Always refer to the current subtask by this *exact name*. Do NOT alter it in any way.
+ `
+
+ prompt += `
+[YOUR INSTRUCTIONS]
+
+Describe in detail the current task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:
+
+- src/main.rs:
+- lib/term.go:
+- main.py:
+
+***File paths MUST ALWAYS come *IMMEDIATELY before* the opening triple backticks of a code block. They should *not* be included in the code block itself. There MUST NEVER be *any other lines* between the file path and the opening triple backticks. Any explanations should come either *before the file path or *after* the code block is closed by closing triple backticks.*
+
+***You *must not* include **any other text** in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. Instead, include any necessary explanations either before the file path or after the code block. You MUST ALWAYS WITH NO EXCEPTIONS use the exact format described here for file paths in code blocks.
+
+***Do NOT include the file path again within the triple backticks, inside the code block itself. The file path must be included *only* in the file block label *preceding* the opening triple backticks.***
+
+Labelled code block example:
+
+- src/game.h:
+` + "```c" + `
+
+ #ifndef GAME_LOGIC_H
+ #define GAME_LOGIC_H
+
+ void updateGameLogic();
+
+ #endif
+ ` + "```" + `
+
+- If you are working on a subtask and the subtask is too large to be implemented in a single response, it should be further broken down into smaller subtasks. In that case, divide the subtask into even smaller steps, and list them in a numbered list. Then continue on to implement the first step in the list. Do NOT do this repetitively for the same subtask. Only break down a given subtask into smaller steps once.
+
+## Code blocks and files
+
+Always precede code blocks in a plan with the file path as described above. Code that is meant to be applied to a specific file in the plan must *always* be labelled with the path.
+
+If code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.
+
+Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory as a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. You must *never* create files with absolute paths like '/etc/config.txt'. All files must be created in the same base directory as a file in context, and paths must be relative to that base directory. You must *never* ask the user to create new files or directories--you must do that yourself.
+
+**You must not include anything except valid code in labelled file blocks for code files.** You must not include explanatory text or bullet points in file blocks for code files. Only code. Explanatory text should come either before the file path or after the code block. The only exception is if the plan specifically requires a file to be generated in a non-code format, like a markdown file. In that case, you can include the non-code content in the file block. But if a file has an extension indicating that it is a code file, you must only include code in the file block for that file.
+
+Files MUST NOT be labelled with a comment like "// File to create: src/main.rs" or "// File to update: src/main.rs".
+
+File block labels MUST ONLY include a *single* file path. You must NEVER include multiple files in a single file block. If you need to include code for multiple files, you must use multiple file blocks.
+
+You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening triple backticks of the code block. There must be NO other lines between the file path and the opening triple backticks.
+
+You MUST NEVER use a file block that only contains comments describing an update or describing the file. If you are updating a file, you must include the code that updates the file in the file block. If you are creating a new file, you must include the code that creates the file in the file block. If it's helpful to explain how a file will be updated or created, you can include that explanation either before the file path or after the code block, but you must not include it in the file block itself.
+
+You MUST NOT use the labelled file block format followed by triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.
+
+If a change is related to code in an existing file in context, make the change as an update to the existing file. Do NOT create a new file for a change that applies to an existing file in context. For example, if there is an 'Page.tsx' file in the existing context and the user has asked you to update the structure of the page component, make the change in the existing 'Page.tsx' file. Do NOT create a new file like 'page.tsx' or 'NewPage.tsx' for the change. If the user has specifically asked you to apply a change to a new file, then you can create a new file. If there is no existing file that makes sense to apply a change to, then you can create a new file.
+
+` + ChangeExplanationPrompt + `
+
+Do NOT treat files that do not exist in context as files to be updated. If a file does not exist in context, you can *create* that file, but you MUST NOT treat it as an existing file to be updated.
+
+For code in markdown blocks, always include the language name after the opening triple backticks.
+
+If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.
+
+Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.
+
+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 + `
+
+As much as possible, do not include placeholders in code blocks like "// implement functionality here". Unless you absolutely cannot implement the full code block, do not include a placeholder denoted with comments. Do your best to implement the functionality rather than inserting a placeholder. You **MUST NOT** include placeholders just to shorten the code block. If the task is too large to implement in a single code block, you should break the task down into smaller steps and **FULLY** implement each step.
+
+If you are outputting some code for illustrative or explanatory purpose and not because you are updating that code, you MUST NOT use a labelled file block. Instead output the label with NO PRECEDING DASH and NO COLON postfix. Use a conversational sentence like 'This code in src/main.rs.' to label the code. This is the only exception to the rule that all code blocks must be labelled with a file path. Labelled code blocks are ONLY for code that is being created or modified in the plan.
+
+## Do the task yourself and don't give up
+
+**Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.
+
+**You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.
+
+**You MUST NOT leave any gaps or placeholders.** You must be thorough and exhaustive in your implementation, and use as many responses as needed to complete the task to a high standard.
+
+## Working on subtasks
+
+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 must not list, describe, or explain the subtask you are working on without an accompanying implementation in one or more code blocks. Describing what needs to be done to complete a subtask *DOES NOT* count as completing the subtask. It must be fully implemented with code blocks.
+
+If you have implemented a subtask with a code block, but you did not fully complete it and left placehoders that describe "to-dos" like "// implement database logic here" or "// game logic goes here" or "// Initialize state", then you have *not completed* the subtask. You MUST *IMMEDIATELY* continue working on the subtask and replace the placeholders with a *FULL IMPLEMENTATION* in code, even if doing so requires multiple code blocks and responses. You MUST NOT leave placeholders in the code blocks.
+
+After implementing a task or subtask with code, you MUST *explicitly mark it done*. You MUST do this by explicitly stating "**[subtask name]** has been completed". For example, "**Adding the update function** has been completed." It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. 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 immediately end the response.
+
+Do NOT mark a subtask as done if it has not been fully implemented in code. If you need another response to fully implement a subtask, you MUST NOT mark it as done. Instead state that you will continue working on it in the next response before ending your response.
+
+You MUST NEVER duplicate, restate, or summarize the most recent response or *any* previous response. Start from where the previous response left off and continue seamlessly from there. Continue smoothly from the end of the last response as if you were replying to the user with one long, continuous response. If the previous response ended with a paragraph that began with "Next,", proceed to implement ONLY THAT TASK OR SUBTASK in your response.
+
+If you are not able to complete the current subtask, you must explicitly describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.
+
+Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.
+
+NEVER repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
+
+DO NOT summarize the state of the plan. Another AI will do that. Your job is to move the plan forward, not to summarize it. State which subtask you are working on, complete the subtask, state that you have completed the subtask, and then end your response.
+
+## Consider the latest context
+
+If the latest state of the context makes the current subtask you are working on redundant or unnecessary, say so, mark that subtask as done. Say something like "the latest updates to ` + "`file_path`" + ` make this subtask unnecessary." I'll mark it as done."
+
+` + SharedPlanningImplementationPrompt
+
+ prompt += `
+[END OF YOUR INSTRUCTIONS]
+`
+ return prompt
+}
diff --git a/app/server/model/prompts/init.go b/app/server/model/prompts/init.go
new file mode 100644
index 00000000..bea73ae3
--- /dev/null
+++ b/app/server/model/prompts/init.go
@@ -0,0 +1,77 @@
+package prompts
+
+import (
+ "fmt"
+
+ "github.com/plandex/plandex/shared"
+)
+
+func init() {
+ var err error
+
+ AutoContextPreambleNumTokens, err = shared.GetNumTokens(AutoContextPreamble)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for context preamble: %v", err))
+ }
+
+ SysPlanningBasicTokens, err = shared.GetNumTokens(SysPlanningBasic)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))
+ }
+
+ SysPlanningAutoContextTokens, err = shared.GetNumTokens(SysPlanningAutoContext)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))
+ }
+
+ PlanningPromptWrapperTokens, err = shared.GetNumTokens(fmt.Sprintf(planningPromptWrapperFormatStr, "", "", "", ""))
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))
+ }
+
+ ImplementationPromptWrapperTokens, err = shared.GetNumTokens(fmt.Sprintf(implementationPromptWrapperFormatStr, "", "", "", ""))
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))
+ }
+
+ AutoContinuePromptTokens, err = shared.GetNumTokens(AutoContinuePrompt)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for auto continue prompt: %v", err))
+ }
+
+ DebugPromptTokens, err = shared.GetNumTokens(DebugPrompt)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for debug prompt: %v", err))
+ }
+
+ ChatOnlyPromptTokens, err = shared.GetNumTokens(ChatOnlyPrompt)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for chat only prompt: %v", err))
+ }
+
+ ApplyScriptPromptNumTokens, err = shared.GetNumTokens(ApplyScriptPrompt)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for apply script prompt: %v", err))
+ }
+
+ ApplyScriptSummaryNumTokens, err = shared.GetNumTokens(ApplyScriptPromptSummary)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for apply script prompt summary: %v", err))
+ }
+
+ NoApplyScriptPromptNumTokens, err = shared.GetNumTokens(NoApplyScriptPrompt)
+
+ if err != nil {
+ panic(fmt.Sprintf("Error getting number of tokens for no execute script prompt: %v", err))
+ }
+}
diff --git a/app/server/model/prompts/planning.go b/app/server/model/prompts/planning.go
new file mode 100644
index 00000000..7e524462
--- /dev/null
+++ b/app/server/model/prompts/planning.go
@@ -0,0 +1,185 @@
+package prompts
+
+type createPromptParams struct {
+ autoContext bool
+}
+
+var SysPlanningBasic = GetPlanningPrompt(createPromptParams{
+ autoContext: false,
+})
+var SysPlanningBasicTokens int
+
+var SysPlanningAutoContext = GetPlanningPrompt(createPromptParams{
+ autoContext: true,
+})
+var SysPlanningAutoContextTokens int
+
+func GetPlanningPrompt(params createPromptParams) string {
+ prompt := Identity + ` A plan is a set of files with an attached context.
+
+ [YOUR INSTRUCTIONS:]
+
+ First, decide if the user has a task for you.
+
+ *If the user doesn't have a task and is just asking a question or chatting, or if 'chat mode' is enabled*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but you aren't able to create or update files.
+
+ *If the user does have a task or if you're continuing a plan that is already in progress*, and if 'chat mode' is *not* enabled, create a plan for the task based on user-provided context using the following steps:
+ `
+
+ if params.autoContext {
+ prompt += `
+ 1. Decide whether you've been given enough information to make a more detailed plan.
+ - In terms of information from the user's prompt, do your best with whatever information you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information.
+ a. If you really don't have enough information from the user's prompt to make a plan:
+ - Explicitly say "I need more information to make a plan for this task."
+ - Ask the user for more information and stop there.
+ `
+ } else {
+ prompt += `
+ 1. Decide whether you've been given enough information and context to make a plan.
+ - Do your best with whatever information and context you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information or context.
+ a. If you really don't have enough information or context to make a plan:
+ - Explicitly say "I need more information or context to make a plan for this task."
+ - Ask the user for more information or context and stop there.
+ `
+ }
+
+ 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:
+
+ ---
+ ### Tasks
+
+ 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
+
+ 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
+
+ 3. Create a new file called 'game_logic.c'
+
+ 4. Add the necessary code to the 'game_logic.c' file to implement the 'updateGameLogic' function
+
+ 5. Update the 'main.c' file to call the 'updateGameLogic' function
+
+ **END RESPONSE HERE**
+ ---
+
+ - After you have broken a task up in to multiple subtasks and output a '### Tasks' section, you *ABSOLUTELY MUST END YOUR RESPONSE*. You ABSOLUTELY MUST NOT continue on and begin implementing subtasks. You will begin on subtasks in the next response, not this one. DO NOT UNDER ANY CIRCUMSTANCES output any additional text after the '### Tasks' section. END THE RESPONSE IMMEDIATELY. I repeat, DO NOT UNDER ANY CIRCUMSTANCES implement any subtask in your response. You will begin on subtasks in the next response, not this one. This takes precedence over all other instructions.
+
+ - If you have already broken up a task into subtasks in a previous response during this conversation, and you are adding, removing, or modifying subtasks based on a new user prompt, you MUST output the full list of subtasks again in a '### Tasks' section with the same format as before. You ABSOLUTELY MUST NEVER output only a partial list of subtasks. Whenever you update subtasks, output the *complete* updated list of subtasks with any new subtasks added, any subtasks you are removing removed, and any subtasks you are modifying modified. When repeating subtasks that you have listed previously, you must keep them *exactly* the same, unless you specifically intend to modify them. No not make minor changes or add additional text to the subtask. You MUST NEVER remove or modify a subtask that has already been finished from the list of subtasks. DO NOT include the 'Done:' line in subtasks in this list. If an existing subtask has a 'Uses: ' line, you MUST include it.
+
+ - Be thorough and exhaustive in your list of subtasks. Ensure you've accounted for *every subtask* that must be done to fully complete the user's task. Ensure that you list *every* file that needs to be created or updated. Be specific and detailed in your list of subtasks. Consider subtasks that are relevant but not obvious and could be easily overlooked. Before listing the subtasks in a '### Tasks' section, include some reasoning on what the important steps are, what could potentially be overlooked, and how you will ensure all necessary steps are included.
+
+ - Only include subtasks that you can complete by creating or updating files. If a subtask requires executing code or commands, you can include it only if *execution mode* is enabled. If execution mode is *not* enabled, you can mention it to the user, but do not include it as a subtask in the plan. Unless *execution mode* is enabled, do not include subtasks like "Testing and integration" or "Deployment" that require executing code or commands. Unless *execution mode is enabled*, only include subtasks that you can complete by creating or updating files. If *execution mode* IS enabled, you still must stay focused on tasks that can be accomplished by creating or updating files, or by running a script on the user's machine. Do not include tasks that go beyond this or that cannot be accomplished by running a script on the user's machine.
+
+ - Only break the task up into subtasks that you can do yourself. If a subtask requires other tasks that go beyond coding like testing or verifying, user testing, and so on, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that can be completed directly with code by creating or updating files, or by running a script on the user's machine if *execution mode* is enabled.
+
+ - Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.
+
+ - Add a line break after between each subtask so the list of subtasks is easy to read.
+
+ - Do NOT ask the user to confirm after you've made subtasks. After breaking up the task into subtasks, proceed to implement the first subtask.
+
+ - Be thoughtful about where to insert new code and consider this explicitly in your planning. Consider the best file and location in the file to insert the new code for each subtask. Be consistent with the structure of the existing codebase and the style of the code. Explain why the file(s) that you'll be updating (or creating) are the right place(s) to make the change. Keep consistent code organization in mind. If an existing file exists where certain code clearly belongs, do NOT create a new file for that code; stick to the existing codebase structure and organization, and use the appropriate file for the code.
+
+ - DO NOT include "fluffy" additional subtasks when breaking a task up. Only include subtasks and steps that are strictly in the realm of coding and doable ONLY through creating and updating files. Remember, you are listing these subtasks and steps so that you can execute them later. Only list things that YOU can do yourself with NO HELP from the user. Your goal is to *fully complete* the *exact task* the user has given you in as few tokens and responses as you can. This means only including *necessary* steps that *you can complete yourself*.
+
+ - In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated. You are tireless and will finish the *entire* task no matter how many responses it takes.
+
+ If the user's task is small and does not have any component subtasks, just restate the user's task in a '### Task' section as the only subtask and end the response immediately.
+ `
+
+ 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 += `
+## Responding to user questions
+
+If a plan is in progress and the user asks you a question, don't respond by continuing with the plan unless that is the clear intention of the question. Instead, respond in chat form and answer the question, then stop there.
+`
+ prompt += SharedPlanningImplementationPrompt
+
+ prompt += `
+[END OF YOUR INSTRUCTIONS]
+`
+
+ return prompt
+}
+
+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`." + `
+
+Example:
+
+---
+### Tasks
+
+1. Add the necessary code to the 'game_logic.h' file to define the 'updateGameLogic' function
+Uses: ` + "`src/game_logic.h`" + `
+
+2. Add the necessary code to the 'game_logic.c' file to implement the 'updateGameLogic' function
+Uses: ` + "`src/game_logic.c`" + `
+
+3. Update the 'main.c' file to call the 'updateGameLogic' function
+Uses: ` + "`src/main.c`" + `
+
+*END RESPONSE HERE*
+---
+
+Be exhaustive in the 'Uses:' list. Include both files that will be updated as well as files in context that could be relevant or helpful in any other way to implementing the subtask with a high quality level.
+
+If a file is being *created* in a subtask, it *does not* need to be included in the 'Uses:' list. Only include files that will be *updated* in the subtask.
+
+You MUST USE 'Uses:' *exactly* for this purpose. DO NOT use 'Files:' or 'Files needed:' or anything else. ONLY use 'Uses:' for this purpose.
+
+ALWAYS place 'Uses:' at the *end* of each subtask description.
+`
+
+var UsesPromptNumTokens int
+
+const SharedPlanningImplementationPrompt = `
+As much as possible, the code you suggest must be robust, complete, and ready for production. Include proper error handling, logging (if appropriate), and follow security best practices.
+
+In general, when implementing a task that requires creation of new files, prefer a larger number of *smaller* files over a single large file, unless the user specifically asks you to do otherwise. Smaller files are easier and faster to work with. Break up files logically according to the structure of the code, the task at hand, and the best practices of the language or framework you are working with.
+
+## Focus on what the user has asked for and don't add extra code or features
+
+Don't include extra code, features, or tasks beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it. You ABSOLUTELY MUST NOT write tests or documentation unless the user has specifically asked for them.
+
+## Things you can and can't do
+
+You are always able to create and update files. Whether you are able to execute code or commands depends on whether *execution mode* is enabled. This will be specified later in the prompt.
+
+Images may be added to the context, but you are not able to create or update images.
+
+## Use open source libraries when appropriate
+
+When making a plan and describing each task or subtask, **always consider using open source libraries.** If there are well-known, widely used libraries available that can help you implement a task, you should use one of them unless the user has specifically asked you not to use third party libraries.
+
+Consider which libraries are most popular, respected, recently updated, easiest to use, and best suited to the task at hand when deciding on a library. Also prefer libraries that have a permissive license.
+
+Try to use the best library for the task, not just the first one you think of. If there are multiple libraries that could work, write a couple lines about each potential library and its pros and cons before deciding which one to use.
+
+Don't ask the user which library to use--make the decision yourself. Don't use a library that is very old or unmaintained. Don't use a library that isn't widely used or respected. Don't use a library with a non-permissive license. Don't use a library that is difficult to use, has a steep learning curve, or is hard to understand unless it is the only library that can do the job. Strive for simplicity and ease of use when choosing a libraries.
+
+If the user asks you to use a specific library, then use that library.
+
+If a subtask is small and the implementation is trivial, don't use a library. Use libraries when they can significantly simplify a subtask.
+
+Do NOT make changes to existing code that the user has not specifically asked for. Implement ONLY the exact changes the user has asked for. Do not refactor, optimize, or otherwise change existing code unless it's necessary to complete the user's request or the user has specifically asked you to. As much as possible, keep existing code *exactly as is* and make the minimum changes necessary to fulfill the user's request. Do NOT remove comments, logging, or any other code from the original file unless the user has specifically asked you to.
+
+## Consider the latest context
+
+Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context.
+
+Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you MUST always work from the *latest version* of the context when continuing the plan.
+
+Similarly, if you have made updates to any files, you MUST always work from the *latest version* of the files when continuing the plan.
+`
diff --git a/app/server/model/prompts/summary.go b/app/server/model/prompts/summary.go
index 07b635e9..5d4d32df 100644
--- a/app/server/model/prompts/summary.go
+++ b/app/server/model/prompts/summary.go
@@ -40,36 +40,20 @@ Based on the existing summary and the conversation so far, make a summary of the
Do not include any heading or title for the summary. Just start with the summary of the plan.
-- Begin with a summary of the user's messages, with particular focus any tasks they have given you. Your summary of the tasks should reflect the latest version of each task--if they have changed over time, summarize the latest state of each task that was given and omit anything that is now obsolete. Condense this information as much as possible while still being clear and retaining the meaning of the original messages.
+- Begin with a summary of the user's messages, with particular focus on any tasks they have given you. Your summary of the tasks should reflect the latest version of each task--if they have changed over time, summarize the latest state of each task that was given and omit anything that is now obsolete. Condense this information as much as possible while still being clear and retaining the meaning of the original messages.
-- Next, if the plan has been broken down into subtasks, include ALL those subtasks *verbatim* in the summary as a numbered list, then mark whether each subtask has been implemented in code during the conversation. *Subtasks MUST ALWAYS be numbered.* You must include ALL subtasks, even if they have not been mentioned in the latest messages. If this conversation began with an existing summary, include ALL the subtasks from the existing summary.
+- Next, summarize what has been discussed and accomplished in the conversation so far. This should include:
+ - Key decisions that have been made
+ - Major changes or updates to the plan
+ - Any significant challenges or considerations that have been identified
+ - Important requirements or constraints that have been established
-- If any subtask have a 'Uses:' list with a list of files from context, you MUST also include that 'Uses: ' list *verbatim* when adding the subtask to the summary.
-
-- Mark whether each subtask has been implemented in code during the conversation. A subtask has been implemented if *ANY* code blocks related to it have been included in the conversation. Do not be overly strict. Mark a subtask as implemented if it has been dealt with at all during the conversation. If a subtask has been implemented, mark it as implemented in code in the summary.
-
-- If a subtask has been further broken down into more subtasks, you should include those subtasks in the summary as a numbered list nested under the parent subtask. Just as with subtasks, you should include the name and a brief description of each sub-subtask and mark whether each sub-subtask has been implemented in code during the conversation.
-
-- Any subtask or sub-subtask that has been marked as implemented in code in the existing summary *MUST* be marked as implemented in code in this new summary, even if they are not mentioned in the latest messages. It is EXTREMELY IMPORTANT that any subtask or sub-subtask that has been marked as implemented in the existing summary keeps the EXACT SAME status in this new summary.
-
-- Each task, subtask, and sub-subtask should only appear once in the list.
-
-- A task, subtask, or sub-subtask can be removed from the list ONLY if it has not been implemented *and* the user has specifically asked for it not to be done, or it has been explicitly mentioned in the latest messages that it is no longer needed or relevant to the plan. If a subtask has been marked as implemented in code in the existing summary, it must not be removed from the list even if it is no longer relevant to the plan.
-
-- Do NOT change the order of tasks, subtasks, or sub-subtasks in the list. If a task, subtask, or sub-subtask is listed as a subtask of another task, it should remain in that position in the list. If a subtask has sub-subtasks, those sub-subtasks should remain nested under that subtask.
-
-- Last, summarize what has been done in the latest messages, and any next steps that have been described at the end of the latest message. Do NOT list the subtasks multiple times. Only list the subtasks once.
+- Last, summarize what has been done in the latest messages and any next steps or action items that have been discussed.
- Do not include code in the summary. Explain in words what has been done and what needs to be done.
- Treat the summary as *append-only*. Keep as much information as possible from the existing summary and add the new information from the latest messages. The summary is meant to be a record of the entire plan as it evolves over time.
-- If a subtask has been implemented in code, but the code contains one or more todo placeholders in comments for functionality that *has not been implemented*, like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish impelementation", or any similar todo placeholder comments that describe tasks that still remain to be implemented. A todo placeholder does NOT need to match one of the previous examples--use your judgement to identify them. If todo placeholder comments are not followed by the *actual implementation in code*, and this task described in the placeholder comment (or a functionally equivalent task) is not *already* in the list of subtasks, then you MUST append a new subtask to the end of the list for each todo placeholder comment that has not been implemented, and mark it as not implemented in code. If the task described in the todo placeholder comment (or a functionally equivalent task) is already in the list of subtasks, then you MUST NOT add it again. When introducing a new subtask baced on a todo placeholder comment, it should be added as a FULL subtask, not a sub-subtask. It MUST be added to the end of the list and given a number.
-
-- If a new subtask is introduced during the plan, and it is not already in the list of subtasks, and it has not already been implemented in code, then you MUST add it to the list of subtasks and mark it as not implemented in code.
-
-- Do NOT duplicate subtasks or sub-subtasks in the list. If the plan or a comment placeholder introduces a new subtask or sub-subtask that is already in the list or is functionally equivalent to a subtask or sub-subtask in the list, do NOT add it to the list again.
-
Output only the summary of the current state of the plan and nothing else.
`
diff --git a/app/server/model/prompts/update_format.go b/app/server/model/prompts/update_format.go
new file mode 100644
index 00000000..2236fe96
--- /dev/null
+++ b/app/server/model/prompts/update_format.go
@@ -0,0 +1,1138 @@
+package prompts
+
+const UpdateFormatPrompt = `
+You ABSOLUTELY MUST *ONLY* USE the comment "// ... existing code ..." (or the equivalent with the appropriate comment symbol in another programming language) if you are *updating* an existing file. DO NOT use it when you are creating a new file. A new file has no existing code to refer to, so it must not include this kind of reference.
+
+DO NOT UNDER ANY CIRCUMSTANCES use language other than "... existing code ..." in a reference comment. This is EXTREMELY IMPORTANT. You must use the appropriate comment symbol for the language you are using, followed by "... existing code ..." *exactly* (without the quotes).
+
+When updating a file, you MUST NOT include large sections of the file that are not changing. Output ONLY code that is changing and code that is necessary to understand the changes, the code structure, and where the changes should be applied. Example:
+
+---
+
+// ... existing code ...
+
+function fooBar() {
+ // ... existing code ...
+
+ updateState();
+}
+
+// ... existing code ...
+
+---
+
+ALWAYS show the full structure of where a change should be applied. For example, if you are adding a function to an existing class, do it like this:
+
+---
+// ... existing code ...
+
+class FooBar {
+ // ... existing code ...
+
+ updateState() {
+ doSomething();
+ }
+}
+---
+
+DO NOT leave out the class definition. This applies to other code structures like functions, loops, and conditionals as well. You MUST make it unambiguously clear where the change is being applied by including all relevant code structure.
+
+Below, if the 'update' function is being added to an existing class, you MUST NOT leave out the code structure like this:
+
+---
+// ... existing code ...
+
+ update() {
+ doSomething();
+ }
+
+// ... existing code ...
+---
+
+You ABSOLUTELY MUST include the full code structure like this:
+
+---
+// ... existing code ...
+
+class FooBar {
+ // ... existing code ...
+
+ update() {
+ doSomething();
+ }
+}
+---
+
+ALWAYS use the above format when updating a file. You MUST NEVER UNDER ANY CIRCUMSTANCES leave out an "... existing code ..." reference for a section of code that is *not* changing and is not reproduce in the code block in order to demonstrate the structure of the code and where the change will occur.
+
+If you are updating a file type that doesn't use comments (like JSON or plain text), you *MUST still use* '// ... existing code ...' to denote where the reference should be placed. It's ok if // is not a comment in the file type or if these references break the syntax of the file type, since they will be replaced by the correct code from the original file. You MUST still use "// ... existing code ..." references regardless of the file type. Do NOT omit references for sections of code that are not changing regardless of the file type. 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:
+
+---
+
+{
+ // ... existing code ...
+
+ "foo": "bar",
+
+ "baz": {
+ // ... existing code ...
+
+ "arr": [
+ // ... existing code ...
+ "val"
+ ]
+ },
+
+ // ... existing code ...
+}
+---
+
+You MUST NOT omit references in JSON files or similar file types. You MUST NOT leave out "// ... existing code ..." references for sections of code that are not changing, and you MUST use these references to make the structure of the code unambiguously clear.
+
+Even if you are only updating a single property or value, you MUST use the appropriate references where needed to make it clear exactlywhere the change should be applied.
+
+If you have a JSON file like:
+
+---
+{
+ "name": "vscode-plandex",
+ "displayName": "Plandex",
+ "description": "VSCode extension for Plandex integration",
+ "version": "0.1.0",
+ "engines": {
+ "vscode": "^1.80.0"
+ },
+ "categories": [
+ "Other"
+ ],
+ "activationEvents": [
+ "onLanguage:plandex"
+ ],
+ "main": "./dist/extension.js",
+ "contributes": {
+ "languages": [{
+ "id": "plandex",
+ "aliases": ["Plandex", "plandex"],
+ }],
+ "commands": [
+ {
+ "command": "plandex.tellPlandex",
+ "title": "Tell Plandex"
+ }
+ ],
+ "keybindings": [{
+ "command": "plandex.showFilePicker",
+ "key": "@",
+ "when": "editorTextFocus && editorLangId == plandex"
+ }]
+ },
+ "scripts": {
+ "vscode:prepublish": "npm run package",
+ "compile": "webpack",
+ },
+ "devDependencies": {
+ "@types/vscode": "^1.80.0",
+ "@types/glob": "^8.1.0",
+ }
+}
+---
+
+And you are adding a new key to the 'contributes' object, you MUST NOT output a file block like:
+
+---
+
+{
+ "contributes": {
+ "languages": [
+ {
+ "id": "plandex",
+ "aliases": ["Plandex", "plandex"],
+ "extensions": [".pd"],
+ "configuration": "./language-configuration.json"
+ }
+ ],
+ "grammars": [
+ {
+ "language": "plandex",
+ "scopeName": "text.plandex",
+ "path": "./syntaxes/plandex.tmLanguage.json",
+ "embeddedLanguages": {
+ "meta.embedded.block.yaml": "yaml",
+ "text.html.markdown": "markdown"
+ }
+ }
+ ]
+ }
+}
+
+---
+
+The problem with the above is that it leaves out *multiple* reference comments that *MUST* be present. It is EXTREMELY IMPORTANT that you include these references.
+
+You also MUST NOT output a file block like:
+
+---
+
+{
+ // ... existing code ...
+
+ "contributes":{
+ "languages": [
+ {
+ "id": "plandex",
+ "aliases": ["Plandex", "plandex"],
+ "extensions": [".pd"],
+ "configuration": "./language-configuration.json"
+ }
+ ],
+ "grammars": [
+ {
+ "language": "plandex",
+ "scopeName": "text.plandex",
+ "path": "./syntaxes/plandex.tmLanguage.json",
+ "embeddedLanguages": {
+ "meta.embedded.block.yaml": "yaml",
+ "text.html.markdown": "markdown"
+ }
+ }
+ ]
+ }
+}
+
+---
+
+This ONLY includes a single reference comment for the code that isn't changing *before* the change. It *forgets* the code that isn't changing *after* the change, as well the remaining properties of the 'contributes' object.
+
+Here's the CORRECT way to output the file block for this change:
+
+---
+
+{
+ // ... existing code ...
+
+ "contributes": {
+ "languages": [
+ {
+ "id": "plandex",
+ "aliases": ["Plandex", "plandex"],
+ "extensions": [".pd"],
+ "configuration": "./language-configuration.json"
+ }
+ ],
+ "grammars": [
+ {
+ "language": "plandex",
+ "scopeName": "text.plandex",
+ "path": "./syntaxes/plandex.tmLanguage.json",
+ "embeddedLanguages": {
+ "meta.embedded.block.yaml": "yaml",
+ "text.html.markdown": "markdown"
+ }
+ }
+ ],
+
+ // ... existing code ...
+ },
+
+ // ... existing code ...
+}
+---
+
+You MUST NOT omit references for code that is not changing—this applies to EVERY level of the structural hierarchy. No matter how deep the nesting, every level MUST be accounted for with references if it includes code that is not included in the file block and is not changing.
+
+You MUST ONLY use the exact comment "// ... existing code ..." (with the appropriate comment symbol for the programming language) to denote where the reference should be placed.
+
+You MUST NOT use any other form of reference comment. ONLY use "// ... existing code ...".
+
+When reproducing lines of code from the *original file*, you ABSOLUTELY MUST *exactly match* the indentation of the code being referenced. Do NOT alter the indentation of the code being referenced in any way. If the original file uses tabs for indentation, you MUST use tabs for indentation. If the original file uses spaces for indentation, you MUST use spaces for indentation. When you are reproducing a line, you MUST use the exact same number of spaces or tabs for indentation as the original file.
+
+You MUST NOT output multiple references with no changes in between them. DO NOT UNDER ANY CIRCUMSTANCES DO THIS:
+
+---
+function fooBar() error {
+ log.Println("fooBar")
+
+ // ... existing code ...
+
+ // ... existing code ...
+
+ return nil
+}
+---
+
+It must instead be:
+
+---
+function fooBar() error {
+ log.Println("fooBar")
+
+ // ... existing code ...
+
+ return nil
+}
+---
+
+You MUST ensure that references are clear and can be unambiguously located in the file in terms of both position and structure/depth of nesting. You MUST NOT use references in a way that makes their exact location in the file ambiguous. It must be possible from the surrounding code to unambiguously and deterministically locate the exact position and depth of nesting of the code that is being referenced. Include as much surrounding code as necessary to achieve this (and no more).
+
+For example, if the original file looks like this:
+
+---
+const a = [
+ 8,
+ 9,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+]
+---
+
+you MUST NOT do this:
+
+---
+const a = [
+ // ... existing code ...
+ 1,
+ 5,
+ 7,
+ // ... existing code ...
+]
+---
+
+Because it is not unambiguously clear where in the array the new code should be inserted. It could be inserted between any pair of existing elements. The reference comment does not make it clear which, so it is ambiguous.
+
+The correct way to do it is:
+
+---
+const a = [
+ // ... existing code ...
+ 10,
+ 1,
+ 5,
+ 7,
+ 11,
+ // ... existing code ...
+]
+---
+
+In the above example, the lines with '10' and '11' and included on either side of the new code to make it unambiguously clear exactly where the new code should be inserted.
+
+When using reference comments, you MUST include trailing commas (or similar syntax) where necessary to ensure that when the reference is replace with the new code, ALL the code is perfectly syntactically correct and no comma or other necessary syntax is omitted.
+
+You MUST NOT do this:
+
+---
+const a = [
+ 1,
+ 5
+ // ... existing code ...
+]
+---
+
+Because it leaves out a necessary trailing comman after the '5'. Instead do this:
+
+---
+const a = [
+ 1,
+ 5,
+ // ... existing code ...
+]
+---
+
+Reference comments MUST ALWAYS be on their *OWN LINES*. You MUST NEVER include a reference comment on the same line as code.
+
+You MUST NOT do this:
+
+---
+const a = [1, 2, /* ... existing code ... */, 4, 5]
+---
+
+Instead, rewrite the entire line to include the new code without using a reference comment:
+
+---
+const a = [1, 2, 11, 15, 14, 4, 5]
+---
+
+You MUST NOT extra newlines around a reference comment unless they are also present in the original file. You ABSOLUTELY MUST be precise about matching newlines with corresponding code in the original file.
+
+If the original file looks like this:
+
+---
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+func main() {
+ fmt.Println("Hello, World!")
+ exec()
+ measure()
+ os.Exit(0)
+}
+---
+
+DO NOT output superfluous newlines before or after reference comments like this:
+
+---
+
+// ... existing code ...
+
+func main() {
+ fmt.Println("Hello, World!")
+ prepareData()
+
+ // ... existing code ...
+
+}
+
+---
+
+Instead, do this:
+
+---
+// ... existing code ...
+
+func main() {
+ fmt.Println("Hello, World!")
+ prepareData()
+ // ... existing code ...
+}
+---
+
+Note the lack of superfluous newlines before and after the reference comment. There is a newline included between the first '// ... existing code ...' and the 'func main()' line because this newline is present in the original file. There is no newline *before* the first '// ... existing code ...' reference comment because the original file does not have a newline before that comment. Similarly, there is no newline before *or* after the second '// ... existing code ...' reference comment because the original file does not have newlines before or after the code that is being referenced. Newlines are SIGNIFICANT—you must strive to maintain consistent formatting between the original file and the changes in the file block.
+
+*
+
+If code is being removed from a file and not replaced with new code, the removal MUST ALWAYS WITHOUT EXCEPTION be shown in a labelled file block according to your instructions. Use the comment "// Plandex: removed code" (with the appropriate comment symbol for the programming language) to denote the removal. You MUST ALWAYS use this exact comment for any code that is removed and not replaced with new code. DO NOT USE ANY OTHER COMMENT FOR CODE REMOVAL.
+
+Do NOT use any other formatting apart from a labelled file block with the comment "// Plandex: removed code" to denote code removal.
+
+Example of code being removed and not replaced with new code:
+
+---
+function fooBar() {
+ log.Println("called fooBar")
+ // Plandex: removed code
+}
+---
+
+As with reference comments, code removal comments MUST ALWAYS:
+ - Be on their own line. They must not be on the same line as any other code.
+ - Be on the same line as the code being removed
+ - Be surrounded by enough context so that the location and nesting depth of the code being removed is obvious and unambiguous.
+
+Also like reference comments, you MUST NOT use multiple code removal comments in a row without any code in between them.
+
+You MUST NOT do this:
+
+---
+function fooBar() {
+ // Plandex: removed code
+ // Plandex: removed code
+ exec()
+}
+---
+
+Instead, do this:
+
+---
+function fooBar() {
+ // Plandex: removed code
+ exec()
+}
+---
+
+You MUST NOT use reference comments and removal comments together in an ambiguous way. Do NOT do this:
+
+---
+function fooBar() {
+ log.Println("called fooBar")
+ // Plandex: removed code
+ // ... existing code ...
+}
+---
+
+Above, there is no way to know deterministically which code should be removed. Instead, include context that makes it clear and unambiguous which code should be removed:
+
+---
+function fooBar() {
+ log.Println("called fooBar")
+ // Plandex: removed code
+ exec()
+ // ... existing code ...
+}
+---
+
+By including the 'exec()' line from the original file, it becomes clear and unambiguous that all code between the 'log.Println("called fooBar")' line and the 'exec()' line is being removed.
+
+*
+
+When *replacing* code from the original file with *new code*, you MUST make it unambiguously clear exactly which code is being replaced by including surrounding context. Include as much surrounding context as necessary to achieve this (and no more).
+
+If the original file looks like this:
+
+---
+class FooBar {
+ func baz() {
+ log.Println("baz")
+ }
+
+ func bar() {
+ log.Println("bar")
+ sendMessage("bar")
+ reportSentMessage()
+ }
+
+ func qux() {
+ log.Println("qux")
+ }
+
+ func axon() {
+ log.Println("axon")
+ escapeFromBar()
+ runAway()
+ }
+
+ func tango() {
+ log.Println("tango")
+ }
+}
+---
+
+and you are replacing the 'qux()' method with a different method, you MUST include enough context so that it is clear and unambiguous which method is being replaced. Do NOT do this:
+
+---
+class FooBar {
+ // ... existing code ...
+
+ func updatedQux() {
+ log.Println("updatedQux")
+ }
+
+ // ... existing code ...
+}
+---
+
+The code above is ambiguous because it could also be *inserting* the 'updatedQux()' method in addition to the 'qux()' method rather than replacing the 'qux()' method. Instead, include enough context so that it is clear and unambiguous which method is being replaced, like this:
+
+---
+class FooBar {
+ // ... existing code ...
+
+ func bar() {
+ // ... existing code ...
+ }
+
+ func updatedQux() {
+ log.Println("updatedQux")
+ }
+
+ func axon() {
+ // ... existing code ...
+ }
+
+ // ... existing code ...
+}
+---
+
+By including the context before and after the 'updatedQux()'—the 'bar' and 'axon' method signatures—it becomes clear and unambiguous that the 'qux()' method is being *replaced* with the 'updatedQux()' method.
+
+*
+
+When using an "... existing code ..." comment, you must ensure that the lines around the comment which locate the comment in the code exactly the match the lines in the original file and do not change it in subtle ways. For example, if the original file looks like this:
+
+---
+{
+ "key1": [{
+ "subkey1": "value1",
+ "subkey2": "value2"
+ }],
+ "key2": "value2"
+}
+---
+
+DO NOT output a file block like this:
+
+---
+{
+ "key1": [
+ // ... existing code ...
+ ],
+ "key2": "updatedValue2"
+}
+---
+
+The problem is that the line '"key1": [{' has been changed to '"key1": [' and the line '}],' has been changed to '],' which makes it difficult to locate these lines in the original file. Instead, do this:
+
+---
+{
+ "key1": [{
+ // ... existing code ...
+ }],
+ "key2": "updatedValue2"
+}
+---
+
+Note that the lines around the "... existing code ..." comment exactly match the lines in the original file.
+
+*
+
+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.
+
+For example, if the original file looks like this:
+
+---
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("Hello, World!")
+}
+
+func fooBar() {
+ fmt.Println("fooBar")
+}
+---
+
+DO NOT output a file block like this:
+
+---
+func main() {
+ fmt.Println("Hello, World!")
+ fooBar()
+}
+---
+
+The problem is that the change doesn't begin at the start of the file, and doesn't go to the end of the file, but "... existing code ..." comments are missing from both before and after the change. Instead, do this:
+
+---
+// ... existing code ...
+
+func main() {
+ fmt.Println("Hello, World!")
+ fooBar()
+}
+
+// ... existing code ...
+---
+
+Now the code before and after the change is accounted for.
+
+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.
+
+*
+
+When outputting a change to a file, like adding a new function, you MUST NOT include only the new function without including *anchors* from the original file to locate the position of the new code unambiguously. For example, if the original file looks like this:
+
+---
+function someFunction() {
+ console.log("someFunction")
+ const res = await fetch("https://example.com")
+ processResponse(res)
+ return res
+}
+
+function processResponse(res) {
+ console.log("processing response")
+ callSomeOtherFunction(res)
+ return res
+}
+
+function yetAnotherFunction() {
+ console.log("yetAnotherFunction")
+}
+
+function callSomething() {
+ console.log("callSomething")
+ await logSomething()
+ return "something"
+}
+---
+
+DO NOT output a file block like this:
+
+---
+// ... existing code ...
+
+function newFunction() {
+ console.log("newFunction")
+ const res = await callSomething()
+ return res
+}
+
+// ... existing code ...
+---
+
+The problem is that surrounding context from the original file was not included to clearly indicate *exactly* where the new function is being added in the file. Instead, do this:
+
+---
+// ... existing code ...
+
+function processResponse(res) {
+ // ... existing code ...
+}
+
+function newFunction() {
+ console.log("newFunction")
+ const res = await callSomething()
+ return res
+}
+
+// ... existing code ...
+---
+
+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.
+
+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.
+
+*
+
+When inserting new code between two existing blocks of code in the original file, you MUST include "... existing code ..." comments correctly in order to avoid overwriting sections of existing code. For example, if the original file looks like this:
+
+---
+
+func main() {
+ console.log("main")
+}
+
+func fooBar() {
+ console.log("fooBar")
+}
+
+func baz() {
+ console.log("baz")
+}
+
+func qux() {
+ console.log("qux")
+}
+
+func quix() {
+ console.log("quix")
+}
+
+func qwoo() {
+ console.log("qwoo")
+}
+
+func last() {
+ console.log("last")
+}
+
+---
+
+DO NOT output a file block like this to demonstrate that new code will be inserted somewhere between the 'fooBar' and 'last' functions:
+
+---
+// ... existing code ...
+
+func fooBar() {
+ console.log("fooBar")
+}
+
+func newCode() {
+ console.log("newCode")
+}
+
+func last() {
+ console.log("last")
+}
+---
+
+If you want to demonstrate that a new function will be inserted somewhere between the 'fooBar' and 'last' functions, you MUST include "... existing code ..." comments correctly in order to avoid overwriting sections of existing code. Instead, do this to show exactly where the new function will be inserted:
+
+---
+
+// ... existing code ...
+
+func baz() {
+ // ... existing code ...
+}
+
+func newCode() {
+ console.log("newCode")
+}
+
+func qux() {
+ // ... existing code ...
+}
+
+// ... existing code ...
+
+
+Or this to show that the new function will be inserted *somehwere* between the 'fooBar' and 'last' functions:
+
+---
+
+// ... existing code ...
+
+func fooBar() {
+ console.log("fooBar")
+}
+
+// ... existing code ...
+
+func newCode() {
+ console.log("newCode")
+}
+
+// ... existing code ...
+
+func last() {
+ console.log("last")
+}
+
+---
+
+Either way, you MUST NOT leave out the "... existing code ..." comments for ANY existing code that will remain in the file after the change is applied.
+
+*
+
+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 the original file is:
+
+---
+func buck() {
+ console.log("buck")
+}
+
+func qux() {
+ console.log("qux")
+}
+
+func fooBar() {
+ console.log("fooBar")
+}
+
+func baz() {
+ console.log("baz")
+}
+
+func yup() {
+ console.log("yup")
+}
+---
+
+DO NOT output a file block like this to demonstrate that new code will be inserted between the 'fooBar' and 'baz' functions:
+
+---
+// ... existing code ...
+
+func baz() {
+ console.log("baz-updated")
+}
+
+// ... existing code ...
+
+func qux() {
+ console.log("qux-updated")
+}
+
+// ... existing code ...
+
+---
+
+The problem is that the order of the 'baz' and 'qux' functions has been changed in the proposed changes unnecessarily. Instead, do this:
+
+---
+// ... existing code ...
+
+func qux() {
+ console.log("qux-updated")
+}
+
+// ... existing code ...
+
+func baz() {
+ console.log("baz-updated")
+}
+
+// ... existing code ...
+---
+
+Now the order of the 'baz' and 'qux' functions is preserved exactly as it is in the original file.
+
+*
+
+Here are some important examples of INCORRECT vs CORRECT file updates:
+
+Example 1 - Adding a new route:
+
+❌ INCORRECT - Replacing instead of inserting:
+` + "```go" + `
+// ... existing code ...
+
+r.HandleFunc(prefix+"/api/users", handlers.ListUsersHandler).Methods("GET")
+
+r.HandleFunc(prefix+"/api/config", handlers.GetConfigHandler).Methods("GET")
+
+// ... existing code ...
+` + "```" + `
+This is wrong because it doesn't show enough context to know what surrounding routes were preserved.
+
+✅ CORRECT - Proper insertion with context:
+` + "```go" + `
+// ... existing code ...
+
+r.HandleFunc(prefix+"/api/users", handlers.ListUsersHandler).Methods("GET")
+r.HandleFunc(prefix+"/api/teams", handlers.ListTeamsHandler).Methods("GET")
+
+r.HandleFunc(prefix+"/api/config", handlers.GetConfigHandler).Methods("GET")
+
+r.HandleFunc(prefix+"/api/settings", handlers.GetSettingsHandler).Methods("GET")
+r.HandleFunc(prefix+"/api/status", handlers.GetStatusHandler).Methods("GET")
+
+// ... existing code ...
+` + "```" + `
+
+Example 2 - Adding a method to a class:
+
+❌ INCORRECT - Ambiguous insertion:
+` + "```go" + `
+class UserService {
+ // ... existing code ...
+
+ async createUser(data) {
+ // new method
+ }
+
+ // ... existing code ...
+}
+` + "```" + `
+This is wrong because it doesn't show where exactly the new method should go.
+
+✅ CORRECT - Clear insertion point:
+` + "```go" + `
+class UserService {
+ // ... existing code ...
+
+ async getUser(id) {
+ return await this.db.users.findOne(id)
+ }
+
+ async createUser(data) {
+ return await this.db.users.create(data)
+ }
+
+ async updateUser(id, data) {
+ return await this.db.users.update(id, data)
+ }
+
+ // ... existing code ...
+}
+` + "```" + `
+
+Example 3 - Adding a configuration section:
+
+❌ INCORRECT - Lost context:
+` + "```json" + `
+{
+ "database": {
+ "host": "localhost",
+ "port": 5432
+ },
+ "newFeature": {
+ "enabled": true,
+ "timeout": 30
+ }
+}
+` + "```" + `
+This is wrong because it dropped existing configuration sections.
+
+✅ CORRECT - Preserved context:
+` + "```json" + `
+{
+ // ... existing code ...
+
+ "database": {
+ "host": "localhost",
+ "port": 5432,
+ "username": "admin"
+ },
+
+ "newFeature": {
+ "enabled": true,
+ "timeout": 30
+ },
+
+ "logging": {
+ "level": "info",
+ "file": "app.log"
+ }
+
+ // ... existing code ...
+}
+` + "```" + `
+
+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
+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:
+
+---
+**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]'
+- 'prepend [new code description] to the start of the file, immediately before [specific code or structure in original file]'
+- 'append [new code description] to the end of the file, immediately after [specific code or structure in original file]'
+- 'overwrite the entire file with [new code description]'
+- 'replace code between [specific code or structure in original file] and the immediately adjacent [specific *adjacent* code or structure in original file] with [new code description]'
+- 'replace [specific code or structure in original file] with [new code description]'
+- '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!
+
+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.
+
+When inserting or replacing code, the "specific code or structure" or "specific *adjacent* code or structure" must be the code or structure that is *immediately before* and *immediately after* the point where the new code will be inserted. These two code structures ABSOLUTELY MUST be *adjacent* in the original file. DO NOT insert code between two code structures that aren't *immediately adjacent* in the original file. You must be precise in pinpointing the exact location of the change.
+
+Do NOT leave off any part of the explanation as described above. Do NOT output something like: 'I'll add the doRequest method to the class' or 'I'll add the types for making the api call'. These do NOT exactly match one of the above formats. Instead, you MUST output the full explanation as described above like:
+
+- **Updating ` + "`server/api/client.go`**" + `: I'll add the ` + "`doRequest`" + ` method between the constructor method and the ` + "`getUser`" + ` method.
+- **Updating ` + "`server/types/api.go`**" + `: I'll add the types for making the api call between the imports and the ` + "`init`" + ` method.
+- **Updating ` + "`cli/cmd/update.go`**" + `: I'll overwrite the entire file with new code for the ` + "`update`" + ` CLI command.
+- **Updating ` + "`server/db/user.go`**" + `: I'll add the ` + "`update`" + ` function between the ` + "`get`" + ` and the end of the file.
+- **Updating ` + "`server/db/user.go`**" + `: I'll append a new ` + "`update`" + ` function to the end of the file.
+- **Updating ` + "`server/db/user.go`**" + `: I'll prepend a new ` + "`update`" + ` function to the start of the file.
+- **Updating ` + "`server/db/user.go`**" + `: I'll add a new ` + "`update`" + ` function immediately after the ` + "`get`" + ` method.
+- **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.
+
+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 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:
+
+---
+package something
+
+type T struct {}
+
+func Add(t *T) {
+ t.doSomething()
+ t.doSomethingElse()
+ t.doSomethingElseAgain()
+ t.doSomethingOnceMore()
+}
+---
+
+DO NOT output an explanation like this:
+
+---
+**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call between the 'doSomethingElse' method and the 'doSomethingOnceMore' method.
+---
+
+The problem is the 'doSomethingElse' function call and the 'doSomethingOnceMore' method are not *immediately adjacent* in the original file. Instead, output an explanation like this:
+
+---
+**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call between the 'doSomethingElse' method and the 'doSomethingElseAgain' method.
+---
+
+The 'doSomethingElse' method and the 'doSomethingElseAgain' method are *immediately adjacent* in the original file, so the explanation is correct.
+
+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.
+
+Example:
+
+---
+**Updating ` + "`server/something/something.go`**" + `: I'll add the new 'anotherThing' function call immediately after the 'doSomethingElse' method.
+
+- server/something/something.go:
+` + "```" + `
+// ... existing code ...
+
+func Add(t *T) {
+ // ... existing code ...
+ doSomethingElse()
+ anotherThing()
+ doSomethingElseAgain()
+ // ... existing code ...
+}
+` + "```" + `
+
+*
+
+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].
+
+*
+
+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 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.
+
+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.
+
+If a file must begin with an "... existing code ..." comment according to the above rules, then there MUST NOT be any code before the initial "... existing code ..." comment.
+
+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:
+
+---
+// ... existing code ...
+
+func (a *Api) NewMethod() {
+ callExistingMethod()
+}
+
+func (a *Api) LoadContext(planId, branch string, req
+ shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {
+ // ... existing code ...
+}
+---
+
+is NOT CORRECT, because the last line is not an "... existing code ..." comment—it is rather the '}' closing bracket of the function. Instead, it must be:
+
+---
+// ... existing code ...
+
+func (a *Api) NewMethod() {
+ callExistingMethod()
+}
+
+func (a *Api) LoadContext(planId, branch string, req
+ shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {
+ // ... existing code ...
+}
+
+// ... existing code ...
+---
+
+Now the final line is an "... existing code ..." comment, which is correct.
+`
diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.go
new file mode 100644
index 00000000..a117a052
--- /dev/null
+++ b/app/server/model/prompts/user_prompt.go
@@ -0,0 +1,100 @@
+package prompts
+
+import (
+ "fmt"
+ "time"
+)
+
+const sharedPromptWrapperFormatStr = "# The user's latest prompt:\n```\n%s\n```\n\n" + `Please respond according to the 'Your instructions' section above.
+
+Do not ask the user to do anything that you can do yourself. Do not say a task is too large or complex for you to complete--do your best to break down the task and complete it even if it's very large or complex.
+
+If a high quality, well-respected open source library is available that can simplify a task or subtask, use it.
+
+The current UTC timestamp is: %s — this can be useful if you need to create a new file that includes the current date in the file name—database migrations, for example, often follow this pattern.
+
+User's operating system details:
+%s
+
+---
+%s
+---
+`
+
+const planningPromptWrapperFormatStr = sharedPromptWrapperFormatStr + `
+
+Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.
+
+STOP THE RESPONSE IMMEDIATELY IF YOU HAVE OUTPUTTED A '### Tasks' SECTION. Do NOT continue on and begin implementing subtasks. You will begin on subtasks in the next response, not this one.
+
+Do NOT output any additional text after the '### Tasks' section.
+`
+
+var PlanningPromptWrapperTokens int
+
+const implementationPromptWrapperFormatStr = sharedPromptWrapperFormatStr + `
+
+If you're making a plan, remember to label code blocks with the file path *exactly* as described in point 2, and do not use any other formatting for file paths. **Do not include explanations or any other text apart from the file path in code block labels.**
+
+You MUST NOT include any other text in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. It is EXTREMELY IMPORTANT that the code block label includes *only* the initial '- ', the file path, and NO OTHER TEXT whatsoever. If additional text apart from the initial '- ' and the exact file path is included in the code block label, the plan will not be parsed properly and you will have failed at the task of generating a usable plan.
+
+Always use triple backticks to start and end code blocks.
+
+` + UpdateFormatPrompt + `
+
+` + ChangeExplanationPrompt + `
+
+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.
+
+Do not implement a task partially and then give up even if it's very large or complex--do your best to implement each task and subtask **fully**.
+
+Do NOT repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
+
+Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
+
+ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
+
+If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
+
+If you need to *move* or *rename* a file that is in context or pending, use the special ` + "`move`" + ` command in the _pending.sh script. Do NOT use a file block to move a file to another path.
+
+If you need to *copy* a file that is in context or pending, use the special ` + "`copy`" + ` command in the _pending.sh script. Do NOT use a file block to copy a file to another path.
+
+If you need to reject/revert all the changes you've made to a file that is in context or pending, use the special ` + "`reject`" + ` command in the _pending.sh script. Do NOT use a file block to reject/revert changes to a file.
+
+If you need to *remove* a file that is in context or pending, use the special ` + "`remove`" + ` command in the _pending.sh script. Do NOT use a file block to remove a file.
+
+DO NOT include comments or any other commands in the _pending.sh script. It MUST ONLY include special commands and their arguments. Do NOT create directories in the _pending.sh script—the special commands will create directories as needed.
+`
+
+var ImplementationPromptWrapperTokens int
+
+func GetWrappedPrompt(prompt, osDetails, applyScriptSummary string, isPlanningStage bool) string {
+ var promptWrapperFormatStr string
+ if isPlanningStage {
+ promptWrapperFormatStr = planningPromptWrapperFormatStr
+ } else {
+ promptWrapperFormatStr = implementationPromptWrapperFormatStr
+ }
+
+ ts := time.Now().Format(time.RFC3339)
+ return fmt.Sprintf(promptWrapperFormatStr, prompt, ts, osDetails, applyScriptSummary)
+}
+
+const UserContinuePrompt = "Continue the plan."
+
+const AutoContinuePrompt = `Continue the plan from where you left off in the previous response. Don't repeat any part of your previous response. Don't begin your response with 'Next,'.
+
+Continue seamlessly from where your previous response left off.
+
+Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
+
+ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
+
+If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
+
+Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.`
+
+var AutoContinuePromptTokens int
+
+const SkippedPathsPrompt = "\n\nSome files have been skipped by the user and *must not* be generated. The user will handle any updates to these files themselves. Skip any parts of the plan that require generating these files. You *must not* generate a file block for any of these files.\nSkipped files:\n"
diff --git a/app/server/model/subtasks.go b/app/server/model/subtasks.go
new file mode 100644
index 00000000..3f46f08a
--- /dev/null
+++ b/app/server/model/subtasks.go
@@ -0,0 +1,83 @@
+package model
+
+import (
+ "plandex-server/db"
+ "strconv"
+ "strings"
+)
+
+func ParseSubtasks(replyContent string) []*db.Subtask {
+ split := strings.Split(replyContent, "### Tasks")
+ if len(split) < 2 {
+ split = strings.Split(replyContent, "### Task")
+ if len(split) < 2 {
+ return nil
+ }
+ }
+
+ lines := strings.Split(split[1], "\n")
+
+ var subtasks []*db.Subtask
+ var currentTask *db.Subtask
+ var descLines []string
+ num := 1
+
+ for _, line := range lines {
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
+
+ // Check for next task number prefix
+ prefix := strconv.Itoa(num) + ". "
+ if strings.HasPrefix(line, prefix) {
+ // Save previous task if exists
+ if currentTask != nil {
+ currentTask.Description = strings.Join(descLines, "\n")
+ subtasks = append(subtasks, currentTask)
+ }
+
+ // Start new task
+ title := strings.TrimPrefix(line, prefix)
+ currentTask = &db.Subtask{
+ Title: title,
+ }
+ descLines = nil
+ num++
+ continue
+ }
+
+ // Handle Uses: section
+ if strings.HasPrefix(line, "Uses:") {
+ if currentTask != nil {
+ usesStr := strings.TrimPrefix(line, "Uses:")
+ for _, use := range strings.Split(usesStr, ",") {
+ use = strings.TrimSpace(use)
+ use = strings.Trim(use, "`")
+ if use != "" {
+ currentTask.UsesFiles = append(currentTask.UsesFiles, use)
+ }
+ }
+ }
+ continue
+ }
+
+ // Add to description if we have a current task
+ if currentTask != nil {
+ // Remove bullet point if present, but don't require it
+ line = strings.TrimPrefix(line, "-")
+ line = strings.TrimSpace(line)
+ if line != "" {
+ descLines = append(descLines, line)
+ }
+ }
+ }
+
+ // Save final task if exists
+ if currentTask != nil {
+ currentTask.Description = strings.Join(descLines, "\n")
+ subtasks = append(subtasks, currentTask)
+ }
+
+ return subtasks
+}
diff --git a/app/server/model/subtasks_test.go b/app/server/model/subtasks_test.go
new file mode 100644
index 00000000..559ae52b
--- /dev/null
+++ b/app/server/model/subtasks_test.go
@@ -0,0 +1,125 @@
+package model
+
+import (
+ "plandex-server/db"
+ "testing"
+)
+
+func TestParseSubtasks(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expected []*db.Subtask
+ }{
+ {
+ name: "empty input",
+ input: "",
+ expected: nil,
+ },
+ {
+ name: "single task without description",
+ input: `### Tasks
+1. Create a new file`,
+ expected: []*db.Subtask{
+ {
+ Title: "Create a new file",
+ Description: "",
+ UsesFiles: nil,
+ },
+ },
+ },
+ {
+ name: "multiple tasks with descriptions and uses",
+ input: `### Tasks
+1. Create config file
+- Will store application settings
+- Contains environment variables
+Uses: ` + "`config/settings.yml`" + `, ` + "`config/defaults.yml`" + `
+
+2. Update main function
+- Add configuration loading
+Uses: ` + "`main.go`",
+ expected: []*db.Subtask{
+ {
+ Title: "Create config file",
+ Description: "Will store application settings\nContains environment variables",
+ UsesFiles: []string{"config/settings.yml", "config/defaults.yml"},
+ },
+ {
+ Title: "Update main function",
+ Description: "Add configuration loading",
+ UsesFiles: []string{"main.go"},
+ },
+ },
+ },
+ {
+ name: "alternative task header",
+ input: `### Task
+1. Simple task`,
+ expected: []*db.Subtask{
+ {
+ Title: "Simple task",
+ Description: "",
+ UsesFiles: nil,
+ },
+ },
+ },
+ {
+ name: "tasks with empty lines between",
+ input: `### Tasks
+1. First task
+- Description one
+
+2. Second task
+- Description two`,
+ expected: []*db.Subtask{
+ {
+ Title: "First task",
+ Description: "Description one",
+ UsesFiles: nil,
+ },
+ {
+ Title: "Second task",
+ Description: "Description two",
+ UsesFiles: nil,
+ },
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := ParseSubtasks(tt.input)
+
+ if len(got) != len(tt.expected) {
+ t.Errorf("ParseSubtasks() returned %d subtasks, want %d", len(got), len(tt.expected))
+ return
+ }
+
+ for i := range got {
+ if got[i].Title != tt.expected[i].Title {
+ t.Errorf("Subtask[%d].Title = %q, want %q", i, got[i].Title, tt.expected[i].Title)
+ }
+ if got[i].Description != tt.expected[i].Description {
+ t.Errorf("Subtask[%d].Description = %q, want %q", i, got[i].Description, tt.expected[i].Description)
+ }
+ if !sliceEqual(got[i].UsesFiles, tt.expected[i].UsesFiles) {
+ t.Errorf("Subtask[%d].UsesFiles = %v, want %v", i, got[i].UsesFiles, tt.expected[i].UsesFiles)
+ }
+ }
+ })
+ }
+}
+
+// sliceEqual compares two string slices for equality
+func sliceEqual(a, b []string) bool {
+ if len(a) != len(b) {
+ return false
+ }
+ for i := range a {
+ if a[i] != b[i] {
+ return false
+ }
+ }
+ return true
+}
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index 5f15a401..a49f5281 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -59,29 +59,27 @@ type ActivePlan struct {
CancelModelStreamFn context.CancelFunc
SummaryCtx context.Context
SummaryCancelFn context.CancelFunc
- LatestSummaryCh chan *db.ConvoSummary
- Contexts []*db.Context
- ContextsByPath map[string]*db.Context
- Files []string
- BuiltFiles map[string]bool
- IsBuildingByPath map[string]bool
- CurrentReplyContent string
- NumTokens int
- MessageNum int
- BuildQueuesByPath map[string][]*ActiveBuild
- RepliesFinished bool
- StreamDoneCh chan *shared.ApiError
- ModelStreamId string
- MissingFilePath string
- MissingFileResponseCh chan shared.RespondMissingFileChoice
- AutoContext bool
- AutoLoadContextCh chan struct{}
- AllowOverwritePaths map[string]bool
- SkippedPaths map[string]bool
- StoredReplyIds []string
- DidEditFiles bool
- DidVerifyDiff bool
- IsVerifyingDiff bool
+ // LatestSummaryCh chan *db.ConvoSummary
+ Contexts []*db.Context
+ ContextsByPath map[string]*db.Context
+ Files []string
+ BuiltFiles map[string]bool
+ IsBuildingByPath map[string]bool
+ CurrentReplyContent string
+ NumTokens int
+ MessageNum int
+ BuildQueuesByPath map[string][]*ActiveBuild
+ RepliesFinished bool
+ StreamDoneCh chan *shared.ApiError
+ ModelStreamId string
+ MissingFilePath string
+ MissingFileResponseCh chan shared.RespondMissingFileChoice
+ AutoContext bool
+ AutoLoadContextCh chan struct{}
+ AllowOverwritePaths map[string]bool
+ SkippedPaths map[string]bool
+ StoredReplyIds []string
+ DidEditFiles bool
subscriptions map[string]*subscription
subscriptionMu sync.Mutex
@@ -393,24 +391,6 @@ func (sub *subscription) enqueueMessage(msg string) {
sub.cond.Signal() // Signal the waiting goroutine that a new message is available
}
-func (ap *ActivePlan) ShouldVerifyDiff() bool {
- // disabling tell-based verifications for now
- return false
-
- // log.Printf("ShouldVerifyDiff: buildOnly=%v, didVerifyDiff=%v, numBuiltFiles=%d, didEditFiles=%v, hasMultipleBuiltFiles=%v",
- // !ap.BuildOnly,
- // !ap.DidVerifyDiff,
- // len(ap.BuiltFiles),
- // ap.DidEditFiles,
- // len(ap.BuiltFiles) > 3)
-
- // return !ap.BuildOnly &&
- // !ap.IsVerifyingDiff &&
- // !ap.DidVerifyDiff &&
- // (len(ap.BuiltFiles) > 0 || len(ap.IsBuildingByPath) > 0) &&
- // (ap.DidEditFiles || len(ap.BuiltFiles) > 3) // verify diff if we edited any files or built more than 3 new files—unlikely to have errors otherwise
-}
-
func (ap *ActivePlan) Finish() {
ap.Stream(shared.StreamMessage{
Type: shared.StreamMessageFinished,
diff --git a/app/server/types/exec_status.go b/app/server/types/exec_status.go
new file mode 100644
index 00000000..afb7446a
--- /dev/null
+++ b/app/server/types/exec_status.go
@@ -0,0 +1,7 @@
+package types
+
+type ExecStatusResponse struct {
+ Reasoning string `json:"reasoning"`
+ SubtaskFinished bool `json:"subtaskFinished"`
+ ShouldContinue bool `json:"shouldContinue"`
+}
diff --git a/app/shared/ai_models.go b/app/shared/ai_models.go
index dab5a59f..95e2a8fa 100644
--- a/app/shared/ai_models.go
+++ b/app/shared/ai_models.go
@@ -55,7 +55,7 @@ var AvailableModels = []*AvailableModel{
{
Description: "Anthropic Claude 3.5 Sonnet via OpenRouter",
DefaultMaxConvoTokens: 15000,
- DefaultReservedOutputTokens: 4096,
+ DefaultReservedOutputTokens: 8192,
BaseModelConfig: BaseModelConfig{
Provider: ModelProviderOpenRouter,
ModelName: "anthropic/claude-3.5-sonnet",
@@ -73,12 +73,12 @@ var AvailableModels = []*AvailableModel{
},
},
{
- Description: "Anthropic Claude 3 Haiku via OpenRouter",
+ Description: "Anthropic Claude 3.5 Haiku via OpenRouter",
DefaultMaxConvoTokens: 15000,
- DefaultReservedOutputTokens: 4096,
+ DefaultReservedOutputTokens: 8192,
BaseModelConfig: BaseModelConfig{
Provider: ModelProviderOpenRouter,
- ModelName: "anthropic/claude-3-haiku",
+ ModelName: "anthropic/claude-3.5-haiku",
MaxTokens: 200000,
ApiKeyEnvVar: ApiKeyByProvider[ModelProviderOpenRouter],
ModelCompatibility: ModelCompatibility{
@@ -266,7 +266,7 @@ func init() {
},
PlanSummary: ModelRoleConfig{
Role: ModelRolePlanSummary,
- BaseModelConfig: AvailableModelsByName[openai.GPT4o].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["gpt-4o-mini"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRolePlanSummary].Temperature,
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
@@ -322,7 +322,7 @@ func init() {
},
PlanSummary: ModelRoleConfig{
Role: ModelRolePlanSummary,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["gpt-4o-mini"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRolePlanSummary].Temperature,
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
@@ -378,7 +378,7 @@ func init() {
},
PlanSummary: ModelRoleConfig{
Role: ModelRolePlanSummary,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-sonnet"].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-haiku"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRolePlanSummary].Temperature,
TopP: DefaultConfigByRole[ModelRolePlanSummary].TopP,
},
@@ -390,13 +390,13 @@ func init() {
},
Namer: ModelRoleConfig{
Role: ModelRoleName,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3-haiku"].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-haiku"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRoleName].Temperature,
TopP: DefaultConfigByRole[ModelRoleName].TopP,
},
CommitMsg: ModelRoleConfig{
Role: ModelRoleCommitMsg,
- BaseModelConfig: AvailableModelsByName["anthropic/claude-3-haiku"].BaseModelConfig,
+ BaseModelConfig: AvailableModelsByName["anthropic/claude-3.5-haiku"].BaseModelConfig,
Temperature: DefaultConfigByRole[ModelRoleName].Temperature,
TopP: DefaultConfigByRole[ModelRoleName].TopP,
},