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: improve file path handling and context operations
Dane Schneidera06c1a20bae6
diff --git a/app/cli/fs/paths.go b/app/cli/fs/paths.goindex a6fa5747..4cd60014 100644--- a/app/cli/fs/paths.go+++ b/app/cli/fs/paths.go@@ -220,10 +220,7 @@ func GetPaths(baseDir, currentDir string) (*types.ProjectPaths, error) {}if info.IsDir() {- if info.Name() == ".git" {- return filepath.SkipDir- }- if strings.HasPrefix(info.Name(), ".plandex") {+ if ShouldSkipDir(info.Name()) {return filepath.SkipDir}@@ -281,6 +278,10 @@ func GetPaths(baseDir, currentDir string) (*types.ProjectPaths, error) {}}+ for dir := range activeDirs {+ allDirs[dir] = true+ }+for dir := range allDirs {allPaths[dir] = true}@@ -294,6 +295,10 @@ func GetPaths(baseDir, currentDir string) (*types.ProjectPaths, error) {delete(activePaths, path)}+ for path := range activePaths {+ allPaths[path] = true+ }+ignoredPaths := map[string]string{}for path := range allPaths {if _, ok := activePaths[path]; !ok {@@ -440,3 +445,48 @@ func IsIgnored(paths *types.ProjectPaths, path, baseDir string) (bool, string, ereturn true, "git", nil}++var skipExactDir = map[string]bool{+ ".git": true,+ "node_modules": true,+ "venv": true,+ ".cache": true,+ "__pycache__": true,+ "cue.mod": true,+ "_build": true,+ ".build": true,+ "DerivedData": true,+ ".gradle": true,+ ".terraform": true,+ ".terragrunt-cache": true,+ ".next": true,+ ".nuxt": true,+ ".bundle": true,+ ".rvm": true,+ ".rbenv": true,+ ".pyenv": true,+ ".nodenv": true,+ ".plenv": true,+ ".nvm": true,+ "vendor": true,+}++var skipPrefixDir = map[string]bool{+ ".plandex": true,+}++func ShouldSkipDir(dirName string) bool {+ for k := range skipExactDir {+ if k == dirName {+ return true+ }+ }++ for k := range skipPrefixDir {+ if strings.HasPrefix(dirName, k) {+ return true+ }+ }++ return false+}diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex 4fbad955..90c4dd98 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -181,7 +181,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {cachedMapPaths = res.CachedByPathfor _, path := range toLoadMapPaths {- if cachedMapPaths[path] {+ if !cachedMapPaths[path] {uncachedMapPaths = append(uncachedMapPaths, path)}}diff --git a/app/cli/lib/context_paths.go b/app/cli/lib/context_paths.goindex bd56918f..affbcd70 100644--- a/app/cli/lib/context_paths.go+++ b/app/cli/lib/context_paths.go@@ -25,7 +25,8 @@ func ParseInputPaths(params ParseInputPathsParams) ([]string, error) {// see if it's a child of any of the fileOrDirPathsfound := falsefor _, p := range fileOrDirPaths {- found, err := fs.IsSubpathOf(p, path, baseDir)+ var err error+ found, err = fs.IsSubpathOf(p, path, baseDir)if err != nil {return nil, fmt.Errorf("error checking if %s is a subpath of %s: %s", path, p, err)}@@ -41,7 +42,6 @@ func ParseInputPaths(params ParseInputPathsParams) ([]string, error) {if projectPaths.AllDirs[path] {if !(loadParams.Recursive || loadParams.NamesOnly || loadParams.DefsOnly) {// log.Println("path", path, "info.Name()", info.Name())-return nil, fmt.Errorf("cannot process directory %s: requires --recursive/-r, --tree, or --map flag", path)}diff --git a/app/cli/lib/context_update.go b/app/cli/lib/context_update.goindex 76a02ea9..88863f57 100644--- a/app/cli/lib/context_update.go+++ b/app/cli/lib/context_update.go@@ -165,7 +165,7 @@ func CheckOutdatedContextWithOutput(quiet, autoConfirm bool, maybeContexts []*sh_, err := UpdateContextWithOutput(UpdateContextParams{Contexts: maybeContexts,OutdatedRes: *outdatedRes,- Req: map[string]*shared.UpdateContextParams{},+ Req: outdatedRes.Req,})if err != nil {return false, false, fmt.Errorf("error updating context: %v", err)@@ -249,6 +249,7 @@ func UpdateContext(params UpdateContextParams) (UpdateContextResult, error) {// log.Println("updated context")// log.Println("res.Msg", res.Msg)msg = res.Msg+ } else {}if len(deleteIds) > 0 {@@ -284,6 +285,11 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Ccontexts = maybeContexts}+ totalTokens := 0+ for _, context := range contexts {+ totalTokens += context.NumTokens+ }+var errs []errorreq := shared.UpdateContextRequest{}@@ -498,20 +504,27 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Chash := sha256.Sum256(bytes)sha := hex.EncodeToString(hash[:])updatedInputShas[path] = sha+ } else {}}// If any files changed, get new mapif len(updatedInputs) > 0 || len(removedMapPaths) > 0 {- // 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)- // }+ // Check total map input size and paths before making API call+ if len(updatedInputs) > shared.MaxContextMapPaths {+ errs = append(errs, fmt.Errorf("total map paths limit exceeded (found %d, limit %d)", len(updatedInputs), shared.MaxContextMapPaths))+ return+ }++ var totalMapSize int64+ for _, input := range updatedInputs {+ totalMapSize += int64(len(input))+ }++ if totalMapSize > shared.MaxContextMapInputSize {+ errs = append(errs, fmt.Errorf("total map size limit exceeded (size %.2f MB, limit %d MB)", float64(totalMapSize)/1024/1024, int(shared.MaxContextMapInputSize)/1024/1024))+ return+ }updatedParts := make(shared.FileMapBodies)for k, v := range context.MapParts {@@ -555,6 +568,8 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.CInputShas: updatedInputShas,RemovedMapPaths: removedMapPaths,}++ } else {}}(context)} else if context.ContextType == shared.ContextURLType {@@ -631,7 +646,8 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.Creturn &types.ContextOutdatedResult{Msg: "Context is up to date",}, nil- } else if doUpdate {+ } else {+outdatedRes = types.ContextOutdatedResult{UpdatedContexts: updatedContexts,RemovedContexts: removedContexts,@@ -644,17 +660,35 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.CNumTreesRemoved: numTreesRemoved,Req: req,}- res, err := UpdateContext(UpdateContextParams{- Contexts: contexts,- OutdatedRes: outdatedRes,- Req: req,- })- if err != nil {- return nil, fmt.Errorf("failed to update context: %v", err)++ if doUpdate {++ res, err := UpdateContext(UpdateContextParams{+ Contexts: contexts,+ OutdatedRes: outdatedRes,+ Req: req,+ })+ if err != nil {+ return nil, fmt.Errorf("failed to update context: %v", err)+ }+ hasConflicts = res.HasConflicts+ msg = res.Msg+ outdatedRes.Msg = msg+ } else {+ tokensDiff := 0+ for _, diff := range tokenDiffsById {+ tokensDiff += diff+ }+ total := totalTokens + tokensDiff+ outdatedRes.Msg = shared.SummaryForUpdateContext(shared.SummaryForUpdateContextParams{+ NumFiles: numFiles,+ NumTrees: numTrees,+ NumUrls: numUrls,+ NumMaps: numMaps,+ TokensDiff: tokensDiff,+ TotalTokens: total,+ })}- hasConflicts = res.HasConflicts- msg = res.Msg- outdatedRes.Msg = msg}if hasConflicts {