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
continuing work on Cwd management
Dane Schneidere9a5951eab39
diff --git a/app/cli/cmd/plans.go b/app/cli/cmd/plans.goindex 10744823..5883cb4e 100644--- a/app/cli/cmd/plans.go+++ b/app/cli/cmd/plans.go@@ -3,6 +3,7 @@ package cmdimport ("fmt""os"+ "path/filepath""strconv""strings"@@ -128,17 +129,17 @@ func plans(cmd *cobra.Command, args []string) {if len(currentProjectPlans) > 0 {fmt.Println()if len(parentProjectIdsWithPaths) > 0 || len(childProjectIdsWithPaths) > 0 {- color.New(color.Bold, color.FgHiYellow).Println("Plans in current directory")+ color.New(color.Bold, color.FgHiMagenta).Println("Plans in current directory")}for i, p := range currentProjectPlans {num := strconv.Itoa(i + 1)if p.Id == lib.CurrentPlanId {- num = color.New(color.Bold, color.FgGreen).Sprint(num)+ num = color.New(color.Bold, color.FgHiGreen).Sprint(num)}var name stringif p.Id == lib.CurrentPlanId {- name = color.New(color.Bold, color.FgGreen).Sprint(p.Name) + color.New(color.FgWhite).Sprint(" π current")+ name = color.New(color.Bold, color.FgHiGreen).Sprint(p.Name) + color.New(color.FgWhite).Sprint(" π current")} else {name = p.Name}@@ -159,7 +160,7 @@ func plans(cmd *cobra.Command, args []string) {var style []tablewriter.Colorsif p.Name == lib.CurrentPlanId {style = []tablewriter.Colors{- {tablewriter.FgGreenColor, tablewriter.Bold},+ {tablewriter.FgHiGreenColor, tablewriter.Bold},}} else {style = []tablewriter.Colors{@@ -172,64 +173,73 @@ func plans(cmd *cobra.Command, args []string) {}table.Render()+fmt.Println()+ term.PrintCmds("", "tell", "new", "cd", "delete-plan")} else {fmt.Println("π€·ββοΈ No plans in current directory")fmt.Println()+ term.PrintCmds("", "new")}- addPathToTreeFn := func(tree treeprint.Tree, pathParts []string, projectId string, isParent bool) {- if len(pathParts) == 0 {- if plans, ok := plansByProjectId[projectId]; ok {- for _, plan := range plans {- tree.AddNode(plan.Name)- }- }- return- }- var fullPath string- if isParent {- fullPath = filepath.Join(fs.Home, strings.Join(pathParts, "/"))- } else {- fullPath = filepath.Join(fs.ProjectRoot, strings.Join(pathParts, "/"))- }- relPath, _ := filepath.Rel(isParent ? fs.Home : fs.ProjectRoot, fullPath)-- branch := tree.FindByValue(relPath)- if branch == nil {- if len(plansByProjectId[projectId]) == 0 {- // If there are no plans for this project, collapse the directories- tree.AddNode(relPath)- } else {- branch = tree.AddBranch(relPath)- addPathToTreeFn(branch, nil, projectId, isParent)- }- }- }+ var addPathToTreeFn func(tree treeprint.Tree, pathParts []string, projectId string, isParent bool)+ addPathToTreeFn = func(tree treeprint.Tree, pathParts []string, projectId string, isParent bool) {+ if len(pathParts) == 0 {+ if plans, ok := plansByProjectId[projectId]; ok {+ for _, plan := range plans {+ tree.AddNode(color.New(color.Bold, color.FgHiGreen).Sprint(plan.Name))+ }+ }+ return+ }+ var fullPath string+ if isParent {+ fullPath = filepath.Join(fs.HomeDir, filepath.Join(pathParts...))+ } else {+ fullPath = filepath.Join(fs.ProjectRoot, filepath.Join(pathParts...))+ }+ pathBase := fs.ProjectRoot+ if isParent {+ pathBase = fs.HomeDir+ }++ relPath, _ := filepath.Rel(pathBase, fullPath)++ branch := tree.FindByValue(relPath)+ if branch == nil {+ if len(plansByProjectId[projectId]) == 0 {+ // If there are no plans for this project, collapse the directories+ tree.AddNode(relPath)+ } else {+ branch = tree.AddBranch(relPath)+ addPathToTreeFn(branch, nil, projectId, isParent)+ }+ }+ }if len(parentProjectIdsWithPaths) > 0 {fmt.Println()- color.New(color.Bold, color.FgHiYellow).Println("Plans in parent directories")+ color.New(color.Bold, color.FgHiMagenta).Println("Plans in parent directories")+ color.New(color.FgWhite).Println("cd into a directory to work on a plan in that directory")parentTree := treeprint.New()for _, p := range parentProjectIdsWithPaths {- relativePath := strings.TrimPrefix(p[0], fs.ProjectRoot+"/")- addPathToTree(parentTree, relativePath, p[1])+ pathParts := strings.Split(strings.TrimPrefix(p[0], fs.HomeDir+"/"),+ "/")+ addPathToTreeFn(parentTree, pathParts, p[1], true)}fmt.Println(parentTree.String())}if len(childProjectIdsWithPaths) > 0 {fmt.Println()- color.New(color.Bold, color.FgHiYellow).Println("Plans in child directories")+ color.New(color.Bold, color.FgHiMagenta).Println("Plans in child directories")+ color.New(color.FgWhite).Println("cd into a directory to work on a plan in that directory")childTree := treeprint.New()for _, p := range childProjectIdsWithPaths {- relativePath := strings.TrimPrefix(p[0], fs.ProjectRoot+"/")- addPathToTree(childTree, relativePath, p[1])+ pathParts := strings.Split(strings.TrimPrefix(p[0],+ fs.ProjectRoot+"/"), "/")+ addPathToTreeFn(childTree, pathParts, p[1], true)}fmt.Println(childTree.String())}-- fmt.Println()-- term.PrintCmds("", "tell", "new", "cd", "delete-plan")}diff --git a/app/cli/fs/fs.go b/app/cli/fs/fs.goindex 12926e74..2bea67c1 100644--- a/app/cli/fs/fs.go+++ b/app/cli/fs/fs.go@@ -1,10 +1,12 @@package fsimport (+ "encoding/json""fmt""os""os/exec""path/filepath"+ "plandex/types""strings""sync"@@ -17,6 +19,7 @@ var ProjectRoot stringvar HomePlandexDir stringvar CacheDir string+var HomeDir stringvar HomeAuthPath stringvar HomeAccountsPath string@@ -31,6 +34,7 @@ func init() {if err != nil {panic("Couldn't find home dir:" + err.Error())}+ HomeDir = homeif os.Getenv("PLANDEX_ENV") == "development" {HomePlandexDir = filepath.Join(home, ".plandex-home-dev")@@ -274,19 +278,28 @@ func GetPlandexIgnore() (*ignore.GitIgnore, error) {return nil, nil}-func GetParentProjectIdsWithPaths() ([][]string, error) {- var parentProjectIds [][]string+func GetParentProjectIdsWithPaths() ([][2]string, error) {+ var parentProjectIds [][2]stringcurrentDir := ProjectRootfor currentDir != "/" {- projectIdPath := filepath.Join(currentDir, ".plandex", "projectId")- if _, err := os.Stat(projectIdPath); err == nil {- data, err := os.ReadFile(projectIdPath)+ plandexDir := findPlandex(currentDir)+ projectSettingsPath := filepath.Join(plandexDir, "project.json")+ if _, err := os.Stat(projectSettingsPath); err == nil {+ bytes, err := os.ReadFile(projectSettingsPath)if err != nil {return nil, fmt.Errorf("error reading projectId file: %s", err)}- projectId := string(data)- parentProjectIds = append(parentProjectIds, []string{currentDir, projectId})++ var settings types.CurrentProjectSettings+ err = json.Unmarshal(bytes, &settings)++ if err != nil {+ panic(fmt.Errorf("error unmarshalling project.json: %v", err))+ }++ projectId := string(settings.Id)+ parentProjectIds = append(parentProjectIds, [2]string{currentDir, projectId})}currentDir = filepath.Dir(currentDir)}@@ -294,29 +307,37 @@ func GetParentProjectIdsWithPaths() ([][]string, error) {return parentProjectIds, nil}-func GetChildProjectIdsWithPaths(dir string) ([][]string, error) {- var childProjectIds [][]string+func GetChildProjectIdsWithPaths() ([][2]string, error) {+ var childProjectIds [][2]string- err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {+ err := filepath.Walk(Cwd, func(path string, info os.FileInfo, err error) error {if err != nil {return err}if info.IsDir() {- projectIdPath := filepath.Join(path, ".plandex", "projectId")- if _, err := os.Stat(projectIdPath); err == nil {- data, err := os.ReadFile(projectIdPath)+ plandexDir := findPlandex(path)+ projectSettingsPath := filepath.Join(plandexDir, "project.json")+ if _, err := os.Stat(projectSettingsPath); err == nil {+ bytes, err := os.ReadFile(projectSettingsPath)if err != nil {return fmt.Errorf("error reading projectId file: %s", err)}- projectId := string(data)- childProjectIds = append(childProjectIds, []string{path, projectId})+ var settings types.CurrentProjectSettings+ err = json.Unmarshal(bytes, &settings)++ if err != nil {+ panic(fmt.Errorf("error unmarshalling project.json: %v", err))+ }++ projectId := string(settings.Id)+ childProjectIds = append(childProjectIds, [2]string{path, projectId})}}return nil})if err != nil {- return nil, fmt.Errorf("error walking the path %s: %s", dir, err)+ return nil, fmt.Errorf("error walking the path %s: %s", Cwd, err)}return childProjectIds, nildiff --git a/app/cli/go.mod b/app/cli/go.modindex e5d2f7f9..c4c3f1f3 100644--- a/app/cli/go.mod+++ b/app/cli/go.mod@@ -60,6 +60,7 @@ require (github.com/plandex/plandex/shared v0.0.0-00010101000000-000000000000github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06github.com/spf13/pflag v1.0.5 // indirect+ github.com/xlab/treeprint v1.2.0golang.org/x/crypto v0.19.0golang.org/x/text v0.14.0 // indirect)diff --git a/app/cli/go.sum b/app/cli/go.sumindex 97bf9c1a..cd221d4f 100644--- a/app/cli/go.sum+++ b/app/cli/go.sum@@ -682,6 +682,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=+github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=+github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=diff --git a/app/server/db/models.go b/app/server/db/models.goindex 58c9bba0..4b5b2848 100644--- a/app/server/db/models.go+++ b/app/server/db/models.go@@ -141,6 +141,7 @@ func (plan *Plan) ToApi() *shared.Plan {return &shared.Plan{Id: plan.Id,OwnerId: plan.OwnerId,+ ProjectId: plan.ProjectId,Name: plan.Name,SharedWithOrgAt: plan.SharedWithOrgAt,TotalReplies: plan.TotalReplies,diff --git a/app/shared/models.go b/app/shared/models.goindex 062e5aec..0ff27bcd 100644--- a/app/shared/models.go+++ b/app/shared/models.go@@ -51,6 +51,7 @@ const (type Plan struct {Id string `json:"id"`OwnerId string `json:"ownerId"`+ ProjectId string `json:"projectId"`Name string `json:"name"`SharedWithOrgAt *time.Time `json:"sharedWithOrgAt,omitempty"`TotalReplies int `json:"totalReplies"`