Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

don't require/create project just to list plans in a dir

Dane Schneidercc9aec39916d
diff --git a/app/cli/cmd/ls.go b/app/cli/cmd/ls.go
index 7fba56b8..dda82118 100644
--- a/app/cli/cmd/ls.go
+++ b/app/cli/cmd/ls.go
@@ -19,10 +19,10 @@ var contextCmd = &cobra.Command{
Use: "ls",
Aliases: []string{"ls"},
Short: "List everything in context",
- Run: context,
+ Run: listContext,
}
-func context(cmd *cobra.Command, args []string) {
+func listContext(cmd *cobra.Command, args []string) {
auth.MustResolveAuthWithOrg()
lib.MustResolveProject()
diff --git a/app/cli/cmd/plans.go b/app/cli/cmd/plans.go
index 488164ed..38be43a4 100644
--- a/app/cli/cmd/plans.go
+++ b/app/cli/cmd/plans.go
@@ -1,11 +1,14 @@
package cmd
import (
+ "context"
"fmt"
+ "log"
"os"
"path/filepath"
"strconv"
"strings"
+ "time"
"plandex/api"
"plandex/auth"
@@ -35,7 +38,7 @@ var plansCmd = &cobra.Command{
func plans(cmd *cobra.Command, args []string) {
auth.MustResolveAuthWithOrg()
- lib.MustResolveProject()
+ lib.MaybeResolveProject()
errCh := make(chan error)
@@ -55,9 +58,18 @@ func plans(cmd *cobra.Command, args []string) {
}()
go func() {
- res, err := fs.GetChildProjectIdsWithPaths()
+ ctx, _ := context.WithTimeout(context.Background(), 500*time.Millisecond)
+
+ res, err := fs.GetChildProjectIdsWithPaths(ctx)
if err != nil {
+ log.Println(err.Error())
+
+ if err.Error() == "context timeout" {
+ errCh <- nil
+ return
+ }
+
errCh <- fmt.Errorf("error getting child project ids with paths: %v", err)
return
}
@@ -74,7 +86,12 @@ func plans(cmd *cobra.Command, args []string) {
}
}
- projectIds := []string{lib.CurrentProjectId}
+ var projectIds []string
+
+ if lib.CurrentProjectId != "" {
+ projectIds = append(projectIds, lib.CurrentProjectId)
+ }
+
for _, p := range parentProjectIdsWithPaths {
projectIds = append(projectIds, p[1])
}
@@ -82,6 +99,13 @@ func plans(cmd *cobra.Command, args []string) {
projectIds = append(projectIds, p[1])
}
+ if len(projectIds) == 0 {
+ fmt.Println("🤷‍♂️ No plans")
+ fmt.Println()
+ term.PrintCmds("", "new")
+ return
+ }
+
plans, apiErr := api.Client.ListPlans(projectIds)
if apiErr != nil {
@@ -89,6 +113,8 @@ func plans(cmd *cobra.Command, args []string) {
return
}
+ log.Println("listed")
+
if len(plans) == 0 {
fmt.Println("🤷‍♂️ No plans")
fmt.Println()
@@ -197,10 +223,10 @@ func plans(cmd *cobra.Command, args []string) {
var searchBranch string
if isParent {
baseFull := filepath.Join(fs.HomeDir, basePath, base)
- baseRel, _ := filepath.Rel(fs.ProjectRoot, baseFull)
+ baseRel, _ := filepath.Rel(fs.Cwd, baseFull)
searchBranch = fmt.Sprintf("%s (%s)", base, baseRel)
- // log.Println("Project root:", fs.ProjectRoot)
+ // log.Println("Project root:", fs.Cwd)
// log.Println("searchBranch:", searchBranch)
// log.Println("base:", base)
@@ -223,7 +249,7 @@ func plans(cmd *cobra.Command, args []string) {
label := localPath
if isParent {
pathFull := filepath.Join(fs.HomeDir, basePath, localPath)
- pathRel, _ := filepath.Rel(fs.ProjectRoot, pathFull)
+ pathRel, _ := filepath.Rel(fs.Cwd, pathFull)
label = fmt.Sprintf("%s (%s)", localPath, pathRel)
// log.Println("Adding path to tree")
@@ -271,7 +297,7 @@ func plans(cmd *cobra.Command, args []string) {
color.New(color.FgWhite).Println("cd into a directory to work on a plan in that directory")
childTree := treeprint.New()
for _, p := range childProjectIdsWithPaths {
- rel, err := filepath.Rel(fs.ProjectRoot, p[0])
+ rel, err := filepath.Rel(fs.Cwd, p[0])
if err != nil {
fmt.Fprintln(os.Stderr, "Error getting relative path:", err)
diff --git a/app/cli/fs/fs.go b/app/cli/fs/fs.go
index 46f09b00..d9f1aeec 100644
--- a/app/cli/fs/fs.go
+++ b/app/cli/fs/fs.go
@@ -1,6 +1,7 @@
package fs
import (
+ "context"
"encoding/json"
"fmt"
"os"
@@ -280,7 +281,7 @@ func GetPlandexIgnore() (*ignore.GitIgnore, error) {
func GetParentProjectIdsWithPaths() ([][2]string, error) {
var parentProjectIds [][2]string
- currentDir := filepath.Dir(ProjectRoot)
+ currentDir := filepath.Dir(Cwd)
for currentDir != "/" {
plandexDir := findPlandex(currentDir)
@@ -307,13 +308,36 @@ func GetParentProjectIdsWithPaths() ([][2]string, error) {
return parentProjectIds, nil
}
-func GetChildProjectIdsWithPaths() ([][2]string, error) {
+func GetChildProjectIdsWithPaths(ctx context.Context) ([][2]string, error) {
var childProjectIds [][2]string
err := filepath.Walk(Cwd, func(path string, info os.FileInfo, err error) error {
if err != nil {
+ // if permission denied, skip the path
+ if os.IsPermission(err) {
+ if info.IsDir() {
+ return filepath.SkipDir
+ } else {
+ return nil
+ }
+ }
+
return err
}
+
+ if strings.HasPrefix(info.Name(), ".") {
+ if info.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ }
+
+ select {
+ case <-ctx.Done():
+ return fmt.Errorf("context timeout")
+ default:
+ }
+
if info.IsDir() && path != Cwd {
plandexDir := findPlandex(path)
projectSettingsPath := filepath.Join(plandexDir, "project.json")
@@ -337,6 +361,10 @@ func GetChildProjectIdsWithPaths() ([][2]string, error) {
})
if err != nil {
+ if err.Error() == "context timeout" {
+ return childProjectIds, nil
+ }
+
return nil, fmt.Errorf("error walking the path %s: %s", Cwd, err)
}
diff --git a/app/cli/lib/current.go b/app/cli/lib/current.go
index 014fbc72..b7ced7ed 100644
--- a/app/cli/lib/current.go
+++ b/app/cli/lib/current.go
@@ -20,18 +20,28 @@ var HomeCurrentProjectDir string
var HomeCurrentPlanPath string
func MustResolveProject() {
- if fs.PlandexDir == "" {
+ resolveProject(true)
+}
+
+func MaybeResolveProject() {
+ resolveProject(false)
+}
+
+func resolveProject(mustResolve bool) {
+ if fs.PlandexDir == "" && mustResolve {
_, _, err := fs.FindOrCreatePlandex()
if err != nil {
panic(fmt.Errorf("error finding or creating plandex: %v", err))
}
}
- if fs.PlandexDir == "" || fs.ProjectRoot == "" {
+ if (fs.PlandexDir == "" || fs.ProjectRoot == "") && mustResolve {
panic(fmt.Errorf("could not find or create plandex directory"))
}
- log.Println("PlandexDir: ", fs.PlandexDir)
+ if fs.PlandexDir == "" {
+ return
+ }
// check if project.json exists in PlandexDir
path := filepath.Join(fs.PlandexDir, "project.json")