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
cwd/plan tree finished
Dane Schneider4b1e22c03005
diff --git a/app/cli/cmd/plans.go b/app/cli/cmd/plans.goindex c8c15832..488164ed 100644--- a/app/cli/cmd/plans.go+++ b/app/cli/cmd/plans.go@@ -127,9 +127,10 @@ func plans(cmd *cobra.Command, args []string) {table.SetHeader([]string{"#", "Name", "Updated", "Created" /*"Branches",*/, "Branch", "Context", "Convo"})currentProjectPlans := plansByProjectId[lib.CurrentProjectId]- fmt.Println()if len(parentProjectIdsWithPaths) > 0 || len(childProjectIdsWithPaths) > 0 {- color.New(color.Bold, color.FgHiMagenta).Println("Plans in current directory")+ color.New(color.Bold, color.FgHiMagenta).Print("Plans in current directory\n")+ } else {+ fmt.Println()}for i, p := range currentProjectPlans {num := strconv.Itoa(i + 1)@@ -175,130 +176,110 @@ func plans(cmd *cobra.Command, args []string) {table.Render()fmt.Println()- term.PrintCmds("", "tell", "new", "cd", "delete-plan")+ term.PrintCmds("", "new", "cd", "delete-plan")} else {fmt.Println("π€·ββοΈ No plans in current directory")fmt.Println()term.PrintCmds("", "new")}- 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))- }+ var addPathToTreeFn func(tree treeprint.Tree, basePath, localPath, projectId string, isParent bool)+ addPathToTreeFn = func(tree treeprint.Tree, basePath, localPath, projectId string, isParent bool) {+ var base string+ var tail string+ split := strings.Split(localPath, string(os.PathSeparator))++ var baseBranch treeprint.Tree+ for _, part := range split {+ base = filepath.Join(base, part)+ tail = strings.TrimPrefix(localPath, base+string(os.PathSeparator))++ var searchBranch string+ if isParent {+ baseFull := filepath.Join(fs.HomeDir, basePath, base)+ baseRel, _ := filepath.Rel(fs.ProjectRoot, baseFull)+ searchBranch = fmt.Sprintf("%s (%s)", base, baseRel)++ // log.Println("Project root:", fs.ProjectRoot)++ // log.Println("searchBranch:", searchBranch)+ // log.Println("base:", base)+ // log.Println("tail:", tail)+ // log.Println("basePath:", basePath)+ // log.Println("baseFull:", baseFull)+ // log.Println("baseRel:", baseRel)+ } else {+ searchBranch = base}- 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)-- // Updated logic for constructing the tree to ensure correct nesting- var currentBranch treeprint.Tree = tree- for _, part := range strings.Split(relPath, string(os.PathSeparator)) {- found := false- // Since treeprint.Tree does not provide a method to list its branches,- // we maintain a map from paths to tree branches to find or create the correct branch.- existingBranch, exists := pathToBranchMap[part]- if exists {- currentBranch = existingBranch- found = true- }- if !found {- newBranch := currentBranch.AddBranch(part)- pathToBranchMap[part] = newBranch- currentBranch = newBranch+ baseBranch = tree.FindByValue(searchBranch)+ if baseBranch != nil {+ addPathToTreeFn(baseBranch, filepath.Join(basePath, base), tail, projectId, isParent)+ return+ }}- }- if plans, ok := plansByProjectId[projectId]; ok {- for _, plan := range plans {- currentBranch.AddNode(color.New(color.Bold, color.FgHiGreen).Sprint(plan.Name))- }- }+ if baseBranch == nil {+ label := localPath+ if isParent {+ pathFull := filepath.Join(fs.HomeDir, basePath, localPath)+ pathRel, _ := filepath.Rel(fs.ProjectRoot, pathFull)+ label = fmt.Sprintf("%s (%s)", localPath, pathRel)++ // log.Println("Adding path to tree")+ // log.Println("label:", label)+ // log.Println("localPath:", localPath)+ // log.Println("pathFull:", pathFull)+ // log.Println("pathRel:", pathRel)+ // log.Println("basePath:", basePath)+ }++ branch := tree.AddBranch(label)+ plans := plansByProjectId[projectId]- if plans, ok := plansByProjectId[projectId]; ok {- for _, plan := range plans {- currentBranch.AddNode(color.New(color.Bold,- color.FgHiGreen).Sprint(plan.Name))+ for _, p := range plans {+ branch.AddNode(color.New(color.FgHiCyan).Sprint(p.Name))}}+}if len(parentProjectIdsWithPaths) > 0 {fmt.Println()- color.New(color.Bold, color.FgHiMagenta).Println("Plans in parent directories")+ color.New(color.Bold, color.FgHiWhite).Println("Plans in parent directories")color.New(color.FgWhite).Println("cd into a directory to work on a plan in that directory")parentTree := treeprint.NewWithRoot("~")- for _, p := range parentProjectIdsWithPaths {- pathParts := strings.Split(strings.TrimPrefix(p[0], fs.HomeDir+"/"),- "/")- addPathToTreeFn(parentTree, pathParts, p[1], true)++ for i := len(parentProjectIdsWithPaths) - 1; i >= 0; i-- {+ p := parentProjectIdsWithPaths[i]++ rel, err := filepath.Rel(fs.HomeDir, p[0])++ if err != nil {+ fmt.Fprintln(os.Stderr, "Error getting relative path:", err)+ return+ }++ addPathToTreeFn(parentTree, "", rel, p[1], true)}fmt.Println(parentTree.String())}if len(childProjectIdsWithPaths) > 0 {fmt.Println()- color.New(color.Bold, color.FgHiMagenta).Println("Plans in child directories")+ color.New(color.Bold, color.FgHiWhite).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 {- pathParts := strings.Split(strings.TrimPrefix(p[0],- fs.ProjectRoot+"/"), "/")- addPathToTreeFn(childTree, pathParts, p[1], true)- }- fmt.Println(childTree.String())- }-}+ rel, err := filepath.Rel(fs.ProjectRoot, p[0])-func buildTreeWithCorrectHierarchy(parentProjectIdsWithPaths [][2]string) string {- tree := treeprint.New()- pathToNode := make(map[string]treeprint.Tree)-- // Ensure the root node is added to the map- rootPath := "~"- pathToNode[rootPath] = tree-- for _, projectInfo := range parentProjectIdsWithPaths {- path := projectInfo[0]- projectId := projectInfo[1]-- // Split the path into parts to build the hierarchy- pathParts := strings.Split(strings.TrimPrefix(path,- fs.HomeDir+"/"), "/")- currentPath := rootPath- var currentNode treeprint.Tree = tree-- for _, part := range pathParts {- currentPath = filepath.Join(currentPath, part)- // Check if this path is already in the map- if node, exists := pathToNode[currentPath]; exists {- currentNode = node- } else {- // Path not in map, create a new branch and update the map- newNode := currentNode.AddBranch(part)- pathToNode[currentPath] = newNode- currentNode = newNode+ if err != nil {+ fmt.Fprintln(os.Stderr, "Error getting relative path:", err)+ return}- }- // Add the project ID as a node under the current path- currentNode.AddNode(projectId)+ addPathToTreeFn(childTree, "", rel, p[1], false)+ }+ fmt.Println(childTree.String())}-- return tree.String()}diff --git a/app/cli/lib/git.go b/app/cli/lib/git.goindex 9fcbfce0..002c86b7 100644--- a/app/cli/lib/git.go+++ b/app/cli/lib/git.go@@ -116,7 +116,7 @@ func GitStashPop(conflictStrategy string) error {}return nil} else {- return fmt.Errorf("error popping git stash: %v", err)+ return fmt.Errorf("error popping git stash: %v", string(res))}}diff --git a/app/cli/lib/plans.go b/app/cli/lib/plans.goindex 1d50eab3..0bca18d5 100644--- a/app/cli/lib/plans.go+++ b/app/cli/lib/plans.go@@ -7,6 +7,7 @@ import ("path/filepath""plandex/fs""plandex/types"+ "sync")func WriteCurrentPlan(id string) error {@@ -109,6 +110,7 @@ func GetCurrentBranchNamesByPlanId(planIds []string) (map[string]string, error)return nil, fmt.Errorf("no current project")}+ var mu sync.Mutexbranches := make(map[string]string)errCh := make(chan error, len(planIds))for _, planId := range planIds {@@ -117,8 +119,10 @@ func GetCurrentBranchNamesByPlanId(planIds []string) (map[string]string, error)if err != nil {errCh <- fmt.Errorf("error getting plan current branch: %v", err)} else {- errCh <- nil+ mu.Lock()+ defer mu.Unlock()branches[planId] = branch+ errCh <- nil}}(planId)}diff --git a/app/cli/stream_tui/view.go b/app/cli/stream_tui/view.goindex cd72e597..c9c0bcfb 100644--- a/app/cli/stream_tui/view.go+++ b/app/cli/stream_tui/view.go@@ -67,11 +67,7 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {return ""}- if outputStatic && len(m.finishedByPath) == 0 {- return ""- }-- if outputStatic && len(m.finishedByPath) != len(m.tokensByPath) {+ if outputStatic && len(m.finishedByPath) == 0 && len(m.tokensByPath) == 0 {return ""}@@ -83,11 +79,25 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {}lbl := "Building plan "+ bgColor := color.BgGreenif outputStatic {lbl = "Built plan "++ finishedAll := true+ for _, tokens := range m.tokensByPath {+ if tokens > 0 {+ finishedAll = false+ break+ }+ }++ if !finishedAll {+ lbl = "Build incomplete "+ bgColor = color.BgBlue+ }}- head := color.New(color.BgGreen, color.FgHiWhite, color.Bold).Sprint(" π ") + color.New(color.BgGreen, color.FgHiWhite).Sprint(lbl)+ head := color.New(bgColor, color.FgHiWhite, color.Bold).Sprint(" π ") + color.New(color.BgGreen, color.FgHiWhite).Sprint(lbl)filePaths := make([]string, 0, len(m.tokensByPath))for filePath := range m.tokensByPath {diff --git a/app/server/model/plan/build.go b/app/server/model/plan/build.goindex a6bb4e6b..b36b2d3a 100644--- a/app/server/model/plan/build.go+++ b/app/server/model/plan/build.go@@ -556,10 +556,6 @@ func execPlanBuild(client *openai.Client, currentOrgId, currentUserId, branch stif err != nil {log.Printf("Error setting build error: %v\n", err)}-- UpdateActivePlan(activePlan.Id, activePlan.Branch, func(ap *types.ActivePlan) {- ap.IsBuildingByPath[filePath] = false- })}var buildFile func(filePath string, numRetry int, numReplacementRetry int, res *db.PlanFileResult)diff --git a/app/server/types/reply.go b/app/server/types/reply.goindex 14269472..5eb21675 100644--- a/app/server/types/reply.go+++ b/app/server/types/reply.go@@ -1,8 +1,6 @@package typesimport (- "log"- "strconv""strings""github.com/davecgh/go-spew/spew"@@ -96,21 +94,21 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {}prevFullLine := r.lines[r.lineIndex-1]- log.Println("Previous full line:", strconv.Quote(prevFullLine)) // Logging the full line that's being checked+ // log.Println("Previous full line:", strconv.Quote(prevFullLine)) // Logging the full line that's being checkedprevFullLineTrimmed := strings.TrimSpace(prevFullLine)if r.maybeFilePath != "" {- log.Println("Maybe file path is:", r.maybeFilePath) // Logging the maybeFilePath+ // log.Println("Maybe file path is:", r.maybeFilePath) // Logging the maybeFilePathif strings.HasPrefix(prevFullLineTrimmed, "```") {- log.Println("Found opening ticks--confirming file path...") // Logging the confirmed file path+ // log.Println("Found opening ticks--confirming file path...") // Logging the confirmed file pathr.currentFilePath = r.maybeFilePathr.currentFileIdx = len(r.files)r.fileContents = append(r.fileContents, "")r.maybeFilePath = ""r.currentFileLines = []string{}- log.Println("Confirmed file path:", r.currentFilePath) // Logging the confirmed file path+ // log.Println("Confirmed file path:", r.currentFilePath) // Logging the confirmed file pathreturn} else if prevFullLineTrimmed != "" {@@ -120,17 +118,17 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {}if r.currentFilePath == "" {- log.Println("Current file path is empty--checking for possible file path...")+ // log.Println("Current file path is empty--checking for possible file path...")var gotPath stringif lineHasFilePath(prevFullLineTrimmed) {gotPath = extractFilePath(prevFullLineTrimmed)} else {- log.Println("No possible file path detected.", strconv.Quote(prevFullLineTrimmed))+ // log.Println("No possible file path detected.", strconv.Quote(prevFullLineTrimmed))}if gotPath != "" {- log.Println("Detected possible file path:", gotPath) // Logging the possible file path+ // log.Println("Detected possible file path:", gotPath) // Logging the possible file pathif r.maybeFilePath == "" {r.maybeFilePath = gotPath} else {@@ -138,15 +136,15 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {}}} else {- log.Println("Current file path is not empty--adding to current file...")+ // log.Println("Current file path is not empty--adding to current file...")if strings.HasPrefix(prevFullLineTrimmed, "```") {- log.Println("Found closing ticks--adding file to files and resetting current file...")+ // log.Println("Found closing ticks--adding file to files and resetting current file...")r.files = append(r.files, r.currentFilePath)r.currentFilePath = ""spew.Dump(r.files)} else {- log.Println("Adding tokens to current file...") // Logging token addition+ // log.Println("Adding tokens to current file...") // Logging token additionr.fileContents[r.currentFileIdx] += prevFullLine + "\n"r.currentFileLines = append(r.currentFileLines, prevFullLine)