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
fix for file map updates. limit CPU usage for map building.
Dane Schneider7cc3db31e02b
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex d3e9dfd5..b3171698 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -22,6 +22,7 @@ import (func MustLoadContext(resources []string, params *types.LoadContextParams) {if params.DefsOnly {+ fmt.Println("⏳ Building a map can take a while in larger projects.")term.StartSpinner("🗺️ Building map...")} else if params.NamesOnly {term.StartSpinner("🌳 Loading directory tree...")@@ -270,8 +271,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {var numPaths intif params.DefsOnly {for _, path := range flattenedPaths {- ext := filepath.Ext(path)- if shared.HasFileMapSupport(ext) {+ if shared.HasFileMapSupport(path) {numPaths++}}@@ -310,9 +310,8 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {continue // not a child of any input path}- ext := filepath.Ext(path)- if !shared.HasFileMapSupport(ext) {- // not a tree-sitter supported extension+ if !shared.HasFileMapSupport(path) {+ // not a tree-sitter supported file typecontinue}diff --git a/app/cli/lib/context_update.go b/app/cli/lib/context_update.goindex d8b645ab..9dd44b13 100644--- a/app/cli/lib/context_update.go+++ b/app/cli/lib/context_update.go@@ -4,7 +4,6 @@ import ("crypto/sha256""encoding/hex""fmt"- "log""os""plandex/api""plandex/fs"@@ -196,7 +195,7 @@ func CheckOutdatedContext(maybeContexts []*shared.Context) (*types.ContextOutdatfunc checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Context) (*types.ContextOutdatedResult, error) {var contexts []*shared.Context- log.Println("Checking outdated context")+ // log.Println("Checking outdated context")if maybeContexts == nil {var apiErr *shared.ApiError@@ -391,6 +390,7 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.CnewSha := hex.EncodeToString(hash[:])if newSha != currentSha {+ // log.Println("path", path, "newSha", newSha, "currentSha", currentSha)// fmt.Println("path", path, "newSha", newSha, "currentSha", currentSha)content := string(bytes)updatedInputs[path] = content@@ -426,6 +426,8 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.C}if _, ok := context.MapShas[path]; !ok {+ // log.Println("path", path, "not in context.MapShas")+bytes, err := os.ReadFile(path)if err != nil {errs = append(errs, fmt.Errorf("failed to read map file %s: %v", path, err))@@ -441,7 +443,15 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.C}// If any files changed, get new mapif len(updatedInputs) > 0 || len(removedMapPaths) > 0 {- // fmt.Println("updatedInputs", len(updatedInputs), "removedMapPaths", len(removedMapPaths))+ // log.Println("updatedInputs", len(updatedInputs), "removedMapPaths", len(removedMapPaths))+ // log.Println("updatedInputs:")+ // for k := range updatedInputs {+ // log.Println(k)+ // }+ // log.Println("removedMapPaths:")+ // for k := range removedMapPaths {+ // log.Println(k)+ // }updatedParts := make(shared.FileMapBodies)for k, v := range context.MapParts {@@ -560,7 +570,7 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Cvar hasConflicts boolif len(req) == 0 && len(deleteIds) == 0 {- log.Println("return context is up to date res")+ // log.Println("return context is up to date res")return &types.ContextOutdatedResult{Msg: "Context is up to date",}, nildiff --git a/app/plans/plan-config.md b/app/plans/plan-config.mdnew file mode 100644index 00000000..c9fcb877--- /dev/null+++ b/app/plans/plan-config.md@@ -0,0 +1,20 @@+I want to add a plan config feature. It should be loosely modeled+on the plan model settings (often referred to also as just plan settings),+and the 'model packs' feature. I want to store a 'plan_config' JSON field on+the 'plans' table. I also want a 'settings' and a 'set' CLI command.++'settings' shows the current settings (like 'models' cmd) and 'set' allows+updating the settings just like 'set-model'. the server-side updates can also+work similarly to models and model sets. it shouldn't be added to the file+system or use git at all-it should just be stored in the database.++it should have these properties to start:++AutoApply bool AutoCommit bool AutoContext bool NoExec bool AutoDebug bool AutoDebugTries int++Apart from the plan config, I also want a default user-level config with the+same properties. similar to how there's 'set-model' and 'set-model default'-+this should also have a 'set default' command. again use model settings as a+guide.++On the server side, to keep things neater, create new files for the API and DB handlers rather than including them in the existing plan settings handlers.diff --git a/app/server/handlers/file_maps.go b/app/server/handlers/file_maps.goindex a70ddf92..5e416186 100644--- a/app/server/handlers/file_maps.go+++ b/app/server/handlers/file_maps.go@@ -6,11 +6,15 @@ import ("log""net/http""plandex-server/syntax/file_map"+ "runtime"+ "sync""github.com/plandex/plandex/shared")func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {+ log.Println("Received request for GetFileMapHandler")+var req shared.GetFileMapRequestif err := json.NewDecoder(r.Body).Decode(&req); err != nil {http.Error(w, fmt.Sprintf("Error decoding request: %v", err), http.StatusBadRequest)@@ -18,15 +22,37 @@ func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {}maps := make(shared.FileMapBodies)++ // Use half of available CPUs+ cpus := runtime.NumCPU()+ log.Printf("GetFileMapHandler: Available CPUs: %d", cpus)+ maxWorkers := cpus / 2+ if maxWorkers < 1 {+ maxWorkers = 1 // Ensure at least one worker+ }+ log.Printf("GetFileMapHandler: Max workers: %d", maxWorkers)+ sem := make(chan struct{}, maxWorkers)+ wg := sync.WaitGroup{}+ var mu sync.Mutex+for path, input := range req.MapInputs {- fileMap, err := file_map.MapFile(r.Context(), path, []byte(input))- if err != nil {- // Skip files that can't be parsed, just log the error- log.Printf("Error mapping file %s: %v", path, err)- continue- }- maps[path] = fileMap.String()+ wg.Add(1)+ sem <- struct{}{}+ go func(path string, input string) {+ defer wg.Done()+ defer func() { <-sem }()+ fileMap, err := file_map.MapFile(r.Context(), path, []byte(input))+ if err != nil {+ // Skip files that can't be parsed, just log the error+ log.Printf("Error mapping file %s: %v", path, err)+ return+ }+ mu.Lock()+ maps[path] = fileMap.String()+ mu.Unlock()+ }(path, input)}+ wg.Wait()resp := shared.GetFileMapResponse{MapBodies: maps,diff --git a/app/server/syntax/file_map/multi.go b/app/server/syntax/file_map/multi.goindex a28a766e..a8c44c83 100644--- a/app/server/syntax/file_map/multi.go+++ b/app/server/syntax/file_map/multi.go@@ -3,8 +3,10 @@ package file_mapimport ("context""fmt"+ "log""path/filepath""plandex-server/syntax"+ "runtime""sort""strings""sync"@@ -15,12 +17,25 @@ import (// handles concurrent processing of multiple files for mappingfunc ProcessMapFiles(ctx context.Context, inputs map[string]string) (shared.FileMapBodies, error) {+ log.Println("ProcessMapFiles")bodies := make(shared.FileMapBodies, len(inputs))var mu sync.MutexerrCh := make(chan error, len(inputs))+ // Use half of available CPUs+ cpus := runtime.NumCPU()+ log.Printf("ProcessMapFiles: Available CPUs: %d", cpus)+ maxWorkers := cpus / 2+ if maxWorkers < 1 {+ maxWorkers = 1 // Ensure at least one worker+ }+ log.Printf("ProcessMapFiles: Max workers: %d", maxWorkers)++ sem := make(chan struct{}, maxWorkers)+for path, content := range inputs {go func(path, content string) {+ defer func() { <-sem }()fileMap, err := MapFile(ctx, path, []byte(content))if err != nil {errCh <- fmt.Errorf("error mapping file %s: %v", path, err)