Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
improvements for file maps in large projects and on large files. fix for inclusion of map in tell prompt. some prompt reinforcement for key behaviors.
Dane Schneiderbf1a19db5506
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex a24f3607..19de6b3a 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -119,6 +119,11 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {errCh := make(chan error)ignoredPaths := make(map[string]string)+ mapFilesSkippedTooLarge := []struct {+ Path string+ Size int64+ }{}+ mapFilesSkippedAfterSizeLimit := []string{}numRoutines := 0@@ -145,6 +150,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {if len(inputFilePaths) > 0 {mapInputsByPath := map[string]shared.FileMapInputs{}toLoadMapPaths := []string{}+var mapSize int64if params.DefsOnly {@@ -360,7 +366,9 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {numPaths = len(flattenedPaths)}- if numPaths > shared.MaxContextCount {+ if (params.DefsOnly || params.NamesOnly) && numPaths > shared.MaxContextMapPaths {+ onErr(fmt.Errorf("too many files to load (found %d, limit is %d)", numPaths, shared.MaxContextMapPaths))+ } else if !params.DefsOnly && !params.NamesOnly && numPaths > shared.MaxContextCount {onErr(fmt.Errorf("too many files to load (found %d, limit is %d)", numPaths, shared.MaxContextCount))}@@ -434,7 +442,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {size = fileInfo.Size()- if size > shared.MaxContextBodySize {+ if !params.DefsOnly && size > shared.MaxContextBodySize {errCh <- fmt.Errorf("file %s exceeds size limit (size %.2f MB, limit %d MB)", path, float64(fileInfo.Size())/1024/1024, int(shared.MaxContextBodySize)/1024/1024)return}@@ -449,17 +457,27 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {defer contextMu.Unlock()if params.DefsOnly {- if mapSize+size > shared.MaxContextMapInputSize {- errCh <- fmt.Errorf("map size limit exceeded (size %.2f MB, limit %d MB)", float64(mapSize+size)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)+ if size > shared.MaxContextBodySize {+ mapFilesSkippedTooLarge = append(mapFilesSkippedTooLarge, struct {+ Path string+ Size int64+ }{Path: path, Size: size})+ errCh <- nilreturn}- if len(mapInputsByPath[mapInputPath])+1 > shared.MaxContextMapPaths {- errCh <- fmt.Errorf("map paths limit exceeded (found %d, limit %d)", len(mapInputsByPath[mapInputPath])+1, shared.MaxContextMapPaths)- return+ var mapSizeExceeded bool+ if mapSize+size > shared.MaxContextMapInputSize {+ mapSizeExceeded = true+ mapFilesSkippedAfterSizeLimit = append(mapFilesSkippedAfterSizeLimit, path)}- mapInputsByPath[mapInputPath][path] = string(fileContent)+ content := string(fileContent)+ if mapSizeExceeded {+ content = ""+ }++ mapInputsByPath[mapInputPath][path] = contentmapSize += size} else if isImage {loadContextReq = append(loadContextReq, &shared.LoadContextParams{@@ -655,6 +673,10 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {if len(ignoredPaths) > 0 && !params.SkipIgnoreWarning {printIgnoredMsg()}++ if len(mapFilesSkippedTooLarge) > 0 || len(mapFilesSkippedAfterSizeLimit) > 0 {+ printSkippedMapFilesMsg(mapFilesSkippedTooLarge, mapFilesSkippedAfterSizeLimit)+ }}func AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {@@ -741,3 +763,24 @@ func printIgnoredMsg() {fmt.Println()fmt.Println("ℹ️ " + color.New(color.FgWhite).Sprint("Due to .gitignore or .plandexignore, some paths weren't loaded.\nUse --force / -f to load ignored paths."))}++func printSkippedMapFilesMsg(mapFilesSkippedTooLarge []struct {+ Path string+ Size int64+}, mapFilesSkippedAfterSizeLimit []string) {+ fmt.Println()+ if len(mapFilesSkippedTooLarge) > 0 {+ fmt.Println("ℹ️ These files were skipped because they're too large to map:")+ for _, file := range mapFilesSkippedTooLarge {+ fmt.Printf(" • %s - %d MB\n", file.Path, file.Size/1024/1024)+ }+ }+ if len(mapFilesSkippedAfterSizeLimit) > 0 {+ fmt.Println("ℹ️ These files were skipped because the total map size limit was exceeded:")+ for _, file := range mapFilesSkippedAfterSizeLimit {+ fmt.Printf(" • %s\n", file)+ }+ fmt.Println()+ fmt.Println("They will still be included in the map as paths in the project, but no maps will be generated for them.")+ }+}diff --git a/app/server/handlers/file_maps.go b/app/server/handlers/file_maps.goindex 8ea24331..b8b688f7 100644--- a/app/server/handlers/file_maps.go+++ b/app/server/handlers/file_maps.go@@ -42,8 +42,10 @@ func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {totalSize += len(input)}- if totalSize > shared.MaxContextMapInputSize {- http.Error(w, fmt.Sprintf("Too many files to map: %d (max %d)", totalSize, shared.MaxContextMapInputSize), http.StatusBadRequest)+ // Allow a little extra space for empty file maps after the total size limit is exceeded+ // On the client, once the total size limit is exceeded, we send empty file maps for remaining files+ if totalSize > shared.MaxContextMapInputSize+10000 {+ http.Error(w, fmt.Sprintf("Max map size exceeded: %d (max %d)", totalSize, shared.MaxContextMapInputSize), http.StatusBadRequest)return}diff --git a/app/server/model/plan/tell_context.go b/app/server/model/plan/tell_context.goindex 35e2092a..674e1cb7 100644--- a/app/server/model/plan/tell_context.go+++ b/app/server/model/plan/tell_context.go@@ -17,7 +17,7 @@ type formatModelContextParams struct {includeMaps boolsmartContextEnabled boolexecEnabled bool- basicOnly bool+ baseOnly boolcacheControl boolactiveOnly boolautoOnly bool@@ -32,7 +32,7 @@ func (state *activeTellStreamState) formatModelContext(params formatModelContextexecEnabled := params.execEnabledcurrentStage := state.currentStage- basicOnly := params.basicOnly+ basicOnly := params.baseOnlyactiveOnly := params.activeOnlyautoOnly := params.autoOnlyactivatedPaths := params.activatedPaths@@ -55,13 +55,17 @@ func (state *activeTellStreamState) formatModelContext(params formatModelContextlog.Printf("Tell plan - formatModelContext - uses: %v\n", uses)}+ // log.Println("Tell plan - formatModelContext - state.modelContext:\n", spew.Sdump(state.modelContext))+for _, part := range state.modelContext {- if basicOnly && part.AutoLoaded {- continue- }+ if !(part.ContextType == shared.ContextMapType && includeMaps) {+ if basicOnly && part.AutoLoaded {+ continue+ }- if autoOnly && !part.AutoLoaded {- continue+ if autoOnly && !part.AutoLoaded {+ continue+ }}if currentStage.TellStage == shared.TellStageImplementation && smartContextEnabled && state.currentSubtask != nil && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 033e89c1..f971b607 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -157,7 +157,7 @@ func execTellPlan(params execTellPlanParams) {activatedPaths := state.resolveCurrentStage()- var basicContextMsg *types.ExtendedChatMessagePart+ var baseContextMsg *types.ExtendedChatMessagePartvar autoContextMsg *types.ExtendedChatMessagePartvar smartContextMsg *types.ExtendedChatMessagePart@@ -168,11 +168,11 @@ func execTellPlan(params execTellPlanParams) {execEnabled: req.ExecEnabled,})} else if state.currentStage.TellStage == shared.TellStagePlanning {- basicContextMsg = state.formatModelContext(formatModelContextParams{+ baseContextMsg = state.formatModelContext(formatModelContextParams{includeMaps: true,smartContextEnabled: req.SmartContext,execEnabled: req.ExecEnabled,- basicOnly: true,+ baseOnly: true,cacheControl: true,})@@ -200,10 +200,13 @@ func execTellPlan(params execTellPlanParams) {getTellSysPromptParams := getTellSysPromptParams{autoContextEnabled: state.currentStage.TellStage == shared.TellStagePlanning && state.currentStage.PlanningPhase == shared.PlanningPhaseContext,smartContextEnabled: req.SmartContext,- basicContextMsg: basicContextMsg,+ basicContextMsg: baseContextMsg,autoContextMsg: autoContextMsg,smartContextMsg: smartContextMsg,}++ // log.Println("getTellSysPromptParams:\n", spew.Sdump(getTellSysPromptParams))+sysParts, err := state.getTellSysPrompt(getTellSysPromptParams)if err != nil {log.Printf("Error getting tell sys prompt: %v\n", err)diff --git a/app/server/model/prompts/architect_context.go b/app/server/model/prompts/architect_context.goindex d02fc5e3..9324fa3c 100644--- a/app/server/model/prompts/architect_context.go+++ b/app/server/model/prompts/architect_context.go@@ -68,7 +68,30 @@ Even if context has been loaded previously in the conversation, you MUST load AL---It is CRITICAL to remember that you can only load files which ARE IN THE CODEBASE MAP in the '### Files' section. Do NOT include ANY OTHER FILES except for those which are explicitly listed in the codebase map. Do NOT make up or include files that are not in the codebase map. I know you are capable of following this rule if you give it your full attention.+It is CRITICAL to remember that you can only load files which ARE IN THE CODEBASE MAP *or* have been created during the current plan. Do NOT include ANY OTHER FILES. NEVER guess file paths or assume hypothetical files. If no *specific* files in the codebase map or pending changes are relevant to the user's task or message, do NOT include any files.++Examples:++GOOD:+- Codebase Map includes:+ - ### main.go+ - ### server/server.go+- User Prompt: "Update server to handle new routes."+- ### Files:+ - ` + "`server/server.go`" + ` (relevant symbols here)+- <PlandexFinish/>++BAD:+- Codebase Map includes:+ - ### main.go+ - ### server/server.go+- User Prompt: "Update server to handle new routes."+- ### Files:+ - ` + "`server/server.go`" + ` (ok)+ - ` + "`server/config.yaml`" + ` (BAD - not in map)+ - ` + "`server/router.go`" + ` (BAD - not in map)++Do NOT guess file paths. Do NOT include files not explicitly listed in the codebase map or created during the current plan.`func GetAutoContextTellPrompt(params CreatePromptParams) string {diff --git a/app/server/model/prompts/implement.go b/app/server/model/prompts/implement.goindex 8ca86bbf..3999bae1 100644--- a/app/server/model/prompts/implement.go+++ b/app/server/model/prompts/implement.go@@ -275,7 +275,11 @@ Before marking the task as done, you MUST complete *every* step of the task with`const MarkSubtaskDonePrompt = `-To mark a task done, you MUST:+## Marking Tasks as Done Or In Progress++At the end of your response, you ABSOLUTELY MUST either mark the task as 'done' or mark it as 'in progress', and then output <PlandexFinish/> and immediately end the response.++### To mark a task done:1. Explictly state: "**[task name]** has been completed". For example, "**Adding the update function** has been completed."2. Output <PlandexFinish/>@@ -286,13 +290,19 @@ Example:**Adding the update function** has been completed.<PlandexFinish/>-It's extremely important to mark tasks as done so that you can keep track of what has been completed and what is remaining. You MUST ALWAYS mark tasks done with *exactly* this format. Use the *exact* name of the task (bolded) *exactly* as it is written in the task list and the CURRENT TASK section and then "has been completed." in the response. Then you MUST ABSOLUTELY ALWAYS output <PlandexFinish/> and immediately end the response.+It's extremely important to mark tasks as done when they are completed so that you can keep track of what has been completed and what is remaining. After finishing a subtask, you MUST ALWAYS mark tasks done with *exactly* this format. Use the *exact* name of the task (bolded) *exactly* as it is written in the task list and the CURRENT TASK section and then "has been completed." in the response. Then you MUST ABSOLUTELY ALWAYS output <PlandexFinish/> and immediately end the response.++### To mark a task as in progress:++1. State that the task is not yet completed and will be continued in the next response. For example, "The update function is not yet complete. I will continue working on it in the next response."+2. Output <PlandexFinish/>+3. Immediately end the response.-Before marking the task as done, you MUST complete *every* step of the task. Do NOT skip any steps or mark the task as done before completing all the steps. *All steps must be implemented with code blocks.*+### Important-You ABSOLUTELY MUST NOT mark the task as done by outputting text in the format "**[task name]** has been completed" and outputting <PlandexFinish/> until *every single step* of the task has been implemented with code blocks. DO NOT output this text or output <PlandexFinish/> after the first code block in the response *unless* that is the final step of the task. Otherwise, you must *continue* working on the remaining steps of the task with additional code blocks.+Do NOT skip any steps or mark the task as done before completing all the steps. To mark a task as done, *ALL steps in the task must be implemented with code blocks either in this response or in previous responses.* Otherwise, mark the task as in progress. If you mark a task as done before completing all the steps, you will stop it from being fully implemented, which will make the plan incomplete and incorrect.-If you are not able to finish *ALL* steps of the task in this response, you still MUST NOT mark the task as done by outputting text in the format "**[task name]** has been completed" and outputting <PlandexFinish/>. Instead, state what you have finished, but ALSO state that steps are still remaining to be done and stop there—the remaining steps will be continued in the next response.+## .gitignore filesIf you are updating an existing .gitignore file: DO NOT UNDER ANY CIRCUMSTANCES remove ANY entries. You can only add to it. Be extremely careful in how you edit .gitignore files to be 100% sure you are not remove any files. Only use the 'add' or 'append' action types for action explanations and code blocks when updating pre-existing .gitignore files. This way you can be 100% sure you are not removing any files. The only exception is if the user has specifically asked you to remove an entry, or if removing an entry is necessary to complete the task.diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.goindex b610b95b..686e0b3f 100644--- a/app/server/model/prompts/user_prompt.go+++ b/app/server/model/prompts/user_prompt.go@@ -200,8 +200,6 @@ Do NOT repeat any part of your previous response. Always continue seamlessly froALWAYS 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. 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 + `@@ -219,6 +217,19 @@ If you break up a task into subtasks, only include subtasks that can be implemen`, file, file)s += `+## Is the task done or in progress?++Remember, you must follow these instructions on marking tasks as done or in progress:++- When a subtask is *completed*, you *must* either:++1. Mark it as 'done' in the format described in the 'Marking Tasks as Done Or In Progress' section.+2. Mark it as 'in progress' by explaining that the task is not yet complete and will be continued in the next response.++Remember, you must WAIT until the subtask is *fully implemented* before marking it as done. If a subtask is large, this may require multiple responses. If you have only implemented part of a subtask, do NOT mark it as done. It will be continued in one or more subsequent responses, and the last one of those reponses will mark the subtask as done. If you mark the subtask done prematurely, you will stop it from being fully implemented, which will prevent the plan from being implemented correctly.++## The Most Critical Factor+Remember, the MOST critical factor in creating code blocks correctly is to locate them unambiguously in the file using the definitions that are immediately before and immediately after the the section of code that is being changed or extended. Pay special attention to the 'Context' field in the Action Explanation. ALWAYS include at least a few additional lines of code before and after the section that is changing. And even if you need to include many lines to reach the *definitions* that are immediately before and after the section that is changing, do so.Definitions in the original file that are outside of the section that is changing are like "hooks" that determine where in the resulting file the new code you write will be placed.diff --git a/app/shared/context.go b/app/shared/context.goindex a3190bbf..22cfe9e9 100644--- a/app/shared/context.go+++ b/app/shared/context.go@@ -12,7 +12,7 @@ import (const (MaxContextBodySize = 10 * 1024 * 1024 // 10MBMaxContextCount = 500- MaxContextMapPaths = 10000+ MaxContextMapPaths = 2000MaxContextMapInputSize = 100 * 1024 * 1024 // 100MBMaxTotalContextSize = 2 * 1024 * 1024 * 1024 // 2GB)