Skip to content

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

fixes for more consistent subtask processing. build stall out fix. still add empty map with no files in dir so that it gets updated correctly later.

Dane Schneider9a8498fd0d41
diff --git a/app/cli/cmd/new.go b/app/cli/cmd/new.go
index 1dfc11f3..f3470fcd 100644
--- a/app/cli/cmd/new.go
+++ b/app/cli/cmd/new.go
@@ -98,9 +98,8 @@ func new(cmd *cobra.Command, args []string) {
}
lib.MustLoadContext([]string{baseDir}, &types.LoadContextParams{
- DefsOnly: true,
- SkipIgnoreWarning: true,
- SkipDefsOnlyNoContextOutput: true,
+ DefsOnly: true,
+ SkipIgnoreWarning: true,
})
} else {
fmt.Println()
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index 6d56e756..0a790a90 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -341,14 +341,6 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
if numPaths > shared.MaxContextCount {
onErr(fmt.Errorf("too many files to load (found %d, limit is %d)", numPaths, shared.MaxContextCount))
- } else if numPaths == 0 {
- term.StopSpinner()
- if params.DefsOnly && params.SkipDefsOnlyNoContextOutput {
- fmt.Println()
- } else {
- fmt.Println("🤷‍♂️ No context loaded")
- }
- return
}
inputFilePaths = flattenedPaths
diff --git a/app/cli/types/types.go b/app/cli/types/types.go
index dd3eb7bd..fc84f39f 100644
--- a/app/cli/types/types.go
+++ b/app/cli/types/types.go
@@ -6,14 +6,13 @@ import (
)
type LoadContextParams struct {
- Note string
- Recursive bool
- NamesOnly bool
- ForceSkipIgnore bool
- ImageDetail openai.ImageURLDetail
- DefsOnly bool
- SkipIgnoreWarning bool
- SkipDefsOnlyNoContextOutput bool
+ Note string
+ Recursive bool
+ NamesOnly bool
+ ForceSkipIgnore bool
+ ImageDetail openai.ImageURLDetail
+ DefsOnly bool
+ SkipIgnoreWarning bool
}
type ContextOutdatedResult struct {
diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.go
index 1d39893f..e80aaa81 100644
--- a/app/server/model/plan/build_finish.go
+++ b/app/server/model/plan/build_finish.go
@@ -308,23 +308,21 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanF
return
}
- if fileState.isNewFile {
- buildFinished := false
-
- UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
- ap.BuiltFiles[filePath] = true
- ap.IsBuildingByPath[filePath] = false
- if ap.BuildFinished() {
- buildFinished = true
- }
- })
-
- log.Printf("Finished building file %s\n", filePath)
+ buildFinished := false
- if buildFinished {
- log.Println("Finished building plan, calling onFinishBuild")
- fileState.onFinishBuild()
+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
+ ap.BuiltFiles[filePath] = true
+ ap.IsBuildingByPath[filePath] = false
+ if ap.BuildFinished() {
+ buildFinished = true
}
+ })
+
+ log.Printf("Finished building file %s\n", filePath)
+
+ if buildFinished {
+ log.Println("Finished building plan, calling onFinishBuild")
+ fileState.onFinishBuild()
}
}
diff --git a/app/server/model/plan/tell_context.go b/app/server/model/plan/tell_context.go
index 07bb791f..8f6eece4 100644
--- a/app/server/model/plan/tell_context.go
+++ b/app/server/model/plan/tell_context.go
@@ -7,7 +7,7 @@ import (
"github.com/plandex/plandex/shared"
)
-func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees, isImplementationStage, execEnabled bool) (string, int, error) {
+func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees, isImplementationStage, smartContextEnabled, execEnabled bool) (string, int, error) {
var contextMessages []string = []string{
"### LATEST PLAN CONTEXT ###",
}
@@ -15,7 +15,7 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
addedFilesSet := map[string]bool{}
uses := map[string]bool{}
- if isImplementationStage && state.currentSubtask != nil {
+ if isImplementationStage && smartContextEnabled && state.currentSubtask != nil {
for _, path := range state.currentSubtask.UsesFiles {
uses[path] = true
}
@@ -23,7 +23,7 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
}
for _, part := range state.modelContext {
- if isImplementationStage && state.currentSubtask != nil && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {
+ if isImplementationStage && smartContextEnabled && state.currentSubtask != nil && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {
continue
}
@@ -89,7 +89,7 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
for filePath, body := range state.currentPlanState.CurrentPlanFiles.Files {
if !addedFilesSet[filePath] {
- if isImplementationStage && !uses[filePath] {
+ if isImplementationStage && smartContextEnabled && !uses[filePath] {
continue
}
@@ -109,7 +109,10 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTrees
contextMessages = append(contextMessages, "These files have been *removed* and are no longer in the plan. If you want to re-add them to the plan, you must explicitly create them again.")
}
- if execEnabled {
+ if execEnabled &&
+ // don't show _apply.sh history and content if smart context is enabled and the current subtask doesn't use it
+ !(isImplementationStage && smartContextEnabled && state.currentSubtask != nil && !uses["_apply.sh"]) {
+
contextMessages = append(contextMessages, state.currentPlanState.ExecHistory())
scriptContent, ok := state.currentPlanState.CurrentPlanFiles.Files["_apply.sh"]
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index 82d148e4..54982357 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -159,23 +159,22 @@ func execTellPlan(
}
autoContextEnabled := req.AutoContext && state.hasContextMap
+ smartContextEnabled := req.AutoContext
isPlanningStage := req.IsChatOnly || (!req.IsUserContinue && (iteration == 0 || (autoContextEnabled && iteration == 1)))
isImplementationStage := !isPlanningStage
- isContextStage := isPlanningStage && autoContextEnabled && iteration == 0
+ isContextStage := isPlanningStage && state.hasContextMap && !state.contextMapEmpty && 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
- includeTrees = true
+ includeMaps = true
)
if req.AutoContext && iteration > 1 {
includeMaps = false
- includeTrees = false
}
- modelContextText, modelContextTokens, err := state.formatModelContext(includeMaps, includeTrees, isImplementationStage, req.ExecEnabled)
+ modelContextText, modelContextTokens, err := state.formatModelContext(includeMaps, true, isImplementationStage, smartContextEnabled, req.ExecEnabled)
if err != nil {
err = fmt.Errorf("error formatting model modelContext: %v", err)
log.Println(err)
@@ -194,14 +193,12 @@ func execTellPlan(
if isPlanningStage {
log.Println("isPlanningStage")
- if req.AutoContext && state.hasContextMap {
- if isContextStage {
- sysCreate = prompts.AutoContextPreamble
- sysCreateTokens = prompts.AutoContextPreambleNumTokens
- } else {
- sysCreate = prompts.SysPlanningAutoContext
- sysCreateTokens = prompts.SysPlanningAutoContextTokens
- }
+ if autoContextEnabled && isContextStage {
+ sysCreate = prompts.AutoContextPreamble
+ sysCreateTokens = prompts.AutoContextPreambleNumTokens
+ } else if autoContextEnabled || smartContextEnabled {
+ sysCreate = prompts.SysPlanningAutoContext
+ sysCreateTokens = prompts.SysPlanningAutoContextTokens
} else {
sysCreate = prompts.SysPlanningBasic
sysCreateTokens = prompts.SysPlanningBasicTokens
@@ -603,6 +600,7 @@ func execTellPlan(
},
Temperature: state.settings.ModelPack.Planner.Temperature,
TopP: state.settings.ModelPack.Planner.TopP,
+ Stop: []string{"<PlandexSubtaskDone/>"},
}
envVar := state.settings.ModelPack.Planner.BaseModelConfig.ApiKeyEnvVar
diff --git a/app/server/model/plan/tell_load.go b/app/server/model/plan/tell_load.go
index 369080a3..e74b345e 100644
--- a/app/server/model/plan/tell_load.go
+++ b/app/server/model/plan/tell_load.go
@@ -340,9 +340,13 @@ func (state *activeTellStreamState) loadTellPlan() error {
}
state.hasContextMap = false
+ state.contextMapEmpty = true
for _, context := range state.modelContext {
if context.ContextType == shared.ContextMapType {
state.hasContextMap = true
+ if context.NumTokens > 0 {
+ state.contextMapEmpty = false
+ }
break
}
}
diff --git a/app/server/model/plan/tell_state.go b/app/server/model/plan/tell_state.go
index 0d947467..0795bbc1 100644
--- a/app/server/model/plan/tell_state.go
+++ b/app/server/model/plan/tell_state.go
@@ -21,6 +21,7 @@ type activeTellStreamState struct {
replyId string
modelContext []*db.Context
hasContextMap bool
+ contextMapEmpty bool
convo []*db.ConvoMessage
currentPlanState *shared.CurrentPlanState
missingFileResponse shared.RespondMissingFileChoice
diff --git a/app/server/model/plan/tell_stream_main.go b/app/server/model/plan/tell_stream_main.go
index 9ef58b9c..efd14c44 100644
--- a/app/server/model/plan/tell_stream_main.go
+++ b/app/server/model/plan/tell_stream_main.go
@@ -116,6 +116,14 @@ mainLoop:
return
}
+ // usage can either be included in the final chunk (openrouter) or in a separate chunk (openai)
+ // if the usage chunk is included, handle it and then return out of listener
+ // otherwise keep listening for the usage chunk
+ if response.Usage != nil {
+ state.handleUsageChunk(response.Usage)
+ return
+ }
+
// Reset the timer for the usage chunk
if !timer.Stop() {
<-timer.C
diff --git a/app/server/model/plan/tell_subtasks.go b/app/server/model/plan/tell_subtasks.go
index 282465ce..92473387 100644
--- a/app/server/model/plan/tell_subtasks.go
+++ b/app/server/model/plan/tell_subtasks.go
@@ -16,6 +16,8 @@ func (state *activeTellStreamState) formatSubtasks() (string, int, error) {
var numTokens int
+ var current *db.Subtask
+
for idx, subtask := range state.subtasks {
subtasksText += fmt.Sprintf("%d. %s\n", idx+1, subtask.Title)
if subtask.Description != "" {
@@ -38,12 +40,28 @@ func (state *activeTellStreamState) formatSubtasks() (string, int, error) {
subtasksText += "\n"
if state.currentSubtask != nil && subtask.Title == state.currentSubtask.Title {
+ current = subtask
subtasksText += "Current subtask: yes"
}
subtasksText += "\n"
}
+ if current != nil {
+ subtasksText += fmt.Sprintf("\n### Current subtask\n%s\n", current.Title)
+ if current.Description != "" {
+ subtasksText += "\n" + current.Description + "\n"
+ }
+ if len(current.UsesFiles) > 0 {
+ subtasksText += "Uses: "
+ usesFiles := []string{}
+ for _, file := range current.UsesFiles {
+ usesFiles = append(usesFiles, fmt.Sprintf("`%s`", file))
+ }
+ subtasksText += strings.Join(usesFiles, ", ") + "\n"
+ }
+ }
+
numTokens, err := shared.GetNumTokens(subtasksText)
if err != nil {
return "", 0, fmt.Errorf("error getting num tokens for subtasks: %v", err)
diff --git a/app/server/model/prompts/implement.go b/app/server/model/prompts/implement.go
index f19abbf8..f65176d9 100644
--- a/app/server/model/prompts/implement.go
+++ b/app/server/model/prompts/implement.go
@@ -43,8 +43,6 @@ void updateGameLogic();
#endif
</PlandexBlock>
-- 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.
@@ -95,13 +93,15 @@ If you are outputting some code for illustrative or explanatory purpose and not
## 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.
+` + CurrentSubtaskPrompt + `
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.
+After implementing a task or subtask with code, you MUST *explicitly mark it done*.
+
+` + MarkSubtaskDonePrompt + `
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.
@@ -126,3 +126,22 @@ If the latest state of the context makes the current subtask you are working on
`
return prompt
}
+
+const CurrentSubtaskPrompt = `
+You will implement the *current subtask ONLY* in this response. You MUST NOT implement any other subtasks in this response. When the current subtask is complete, you MUST NOT move on to the next subtask. Instead, you must mark the current subtask as done and then end your response.
+`
+
+const MarkSubtaskDonePrompt = `
+To mark a subtask done, you MUST:
+
+1. Explictly state: "**[subtask name]** has been completed". For example, "**Adding the update function** has been completed."
+2. Output <PlandexSubtaskDone/>
+3. Immediately end the response.
+
+Example:
+
+**Adding the update function** has been completed.
+<PlandexSubtaskDone/>
+
+It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. You MUST ALWAYS mark subtasks done with *exactly* this format. Use the *exact* name of the subtask (bolded) *exactly* as it is written in the subtask list and the CURRENT SUBTASK section and then "has been completed." in the response. Then you MUST ABSOLUTELY ALWAYS output <PlandexSubtaskDone/> and immediately end the response.
+`
diff --git a/app/server/model/prompts/planning.go b/app/server/model/prompts/planning.go
index 4ab74ad2..83a98b28 100644
--- a/app/server/model/prompts/planning.go
+++ b/app/server/model/prompts/planning.go
@@ -140,6 +140,8 @@ If a file is being *created* in a subtask, it *does not* need to be included in
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.
+
+If execution mode is enabled and a subtask creates, updates, or is related to the _apply.sh script, you MUST include ` + "`_apply.sh`" + `in the 'Uses:' list for that subtask.
`
var UsesPromptNumTokens int
diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.go
index 3b5f6085..404c7347 100644
--- a/app/server/model/prompts/user_prompt.go
+++ b/app/server/model/prompts/user_prompt.go
@@ -52,11 +52,13 @@ Do not implement a task partially and then give up even if it's very large or co
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 break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Only include subtasks that require executing code or commands if execution mode is enabled. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
+
+` + CurrentSubtaskPrompt + `
+
+` + MarkSubtaskDonePrompt + `
` + FileOpsPromptSummary
@@ -82,9 +84,13 @@ 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.
+` + CurrentSubtaskPrompt + `
+
+` + MarkSubtaskDonePrompt + `
+
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 break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Only include subtasks that require executing code or commands if execution mode is enabled. 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.`