From 1dc972c8ed073a39ad81c6ac968060a214cd5f83 Mon Sep 17 00:00:00 2001 From: Mahammad Agayev Date: Sun, 30 Jun 2024 15:09:30 +0400 Subject: [PATCH 1/5] [BUGIFX] [CLI] Clean given pathes on plandex load --- app/cli/cmd/load.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/cli/cmd/load.go b/app/cli/cmd/load.go index d1b274ae..3d60d2a0 100644 --- a/app/cli/cmd/load.go +++ b/app/cli/cmd/load.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "path/filepath" "plandex/auth" "plandex/lib" "plandex/term" @@ -45,6 +46,8 @@ func contextLoad(cmd *cobra.Command, args []string) { return } + cleanPaths(args) + lib.MustLoadContext(args, &types.LoadContextParams{ Note: note, Recursive: recursive, @@ -56,3 +59,14 @@ func contextLoad(cmd *cobra.Command, args []string) { fmt.Println() term.PrintCmds("", "ls", "tell") } + +func cleanPaths(paths []string) { + for i := range paths { + paths[i] = filepath.Clean(paths[i]) + + // Remove trailing slash if it's not the root path + if len(paths[i]) > 1 && paths[i][len(paths[i])-1] == '/' { + paths[i] = paths[i][:len(paths[i])-1] + } + } +} From bc7836c40bacd60301f30ce8f8eddd57087e7c4d Mon Sep 17 00:00:00 2001 From: Mahammad Agayev Date: Sat, 6 Jul 2024 13:31:42 +0400 Subject: [PATCH 2/5] Add ensure path utility func&test --- app/cli/utils/utils.go | 9 +++++++++ app/cli/utils/utils_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/cli/utils/utils_test.go diff --git a/app/cli/utils/utils.go b/app/cli/utils/utils.go index 346500bb..9e6f1bb1 100644 --- a/app/cli/utils/utils.go +++ b/app/cli/utils/utils.go @@ -10,3 +10,12 @@ func EnsureMinDuration(start time.Time, minDuration time.Duration) { time.Sleep(minDuration - elapsed) } } + +func EnsureValidPath(path string) string { + // Remove trailing slash if it's not the root path + if len(path) > 1 && path[len(path)-1] == '/' { + path = path[:len(path)-1] + } + + return path +} diff --git a/app/cli/utils/utils_test.go b/app/cli/utils/utils_test.go new file mode 100644 index 00000000..a5127f31 --- /dev/null +++ b/app/cli/utils/utils_test.go @@ -0,0 +1,25 @@ +package utils + +import ( + "testing" +) + +func TestEnsureValidPath(t *testing.T) { + tests := []struct { + input string + expected string + }{ + {"/home/user/", "/home/user"}, + {"/", "/"}, + } + + for _, test := range tests { + t.Run("Path: "+test.input, func(t *testing.T) { + output := EnsureValidPath(test.input) + // t.Logf(output) + if output != test.expected { + t.Errorf("EnsureValidPath(%q) = %q; want %q", test.input, output, test.expected) + } + }) + } +} From 8dc07faff3463d3bbf88d4a007bf19efc0b604cc Mon Sep 17 00:00:00 2001 From: Mahammad Agayev Date: Sat, 6 Jul 2024 14:05:58 +0400 Subject: [PATCH 3/5] Remove clear path for load part --- app/cli/cmd/load.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/cli/cmd/load.go b/app/cli/cmd/load.go index 3d60d2a0..d1b274ae 100644 --- a/app/cli/cmd/load.go +++ b/app/cli/cmd/load.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "path/filepath" "plandex/auth" "plandex/lib" "plandex/term" @@ -46,8 +45,6 @@ func contextLoad(cmd *cobra.Command, args []string) { return } - cleanPaths(args) - lib.MustLoadContext(args, &types.LoadContextParams{ Note: note, Recursive: recursive, @@ -59,14 +56,3 @@ func contextLoad(cmd *cobra.Command, args []string) { fmt.Println() term.PrintCmds("", "ls", "tell") } - -func cleanPaths(paths []string) { - for i := range paths { - paths[i] = filepath.Clean(paths[i]) - - // Remove trailing slash if it's not the root path - if len(paths[i]) > 1 && paths[i][len(paths[i])-1] == '/' { - paths[i] = paths[i][:len(paths[i])-1] - } - } -} From c9ac05f675f1e88c7dd88c9cdeae44d0b0b80160 Mon Sep 17 00:00:00 2001 From: Mahammad Agayev Date: Sat, 6 Jul 2024 14:06:18 +0400 Subject: [PATCH 4/5] Add path clearing to the load context --- app/cli/lib/context_load.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go index 345fd443..ba95d8e2 100644 --- a/app/cli/lib/context_load.go +++ b/app/cli/lib/context_load.go @@ -12,6 +12,7 @@ import ( "plandex/term" "plandex/types" "plandex/url" + "plandex/utils" "strings" "sync" @@ -87,6 +88,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) { resource = resource[2:] } + resource = utils.EnsureValidPath(resource) inputFilePaths = append(inputFilePaths, resource) } } From 9c598a88080e7c1e627cffa3fe0a29230d327ff3 Mon Sep 17 00:00:00 2001 From: Mahammad Agayev Date: Sun, 30 Jun 2024 15:09:30 +0400 Subject: [PATCH 5/5] [BUGIFX] [CLI] Clean given pathes on plandex load Add ensure path utility func&test Remove clear path for load part Add path clearing to the load context --- app/cli/lib/context_load.go | 2 ++ app/cli/utils/utils.go | 9 +++++++++ app/cli/utils/utils_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 app/cli/utils/utils_test.go diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go index 345fd443..ba95d8e2 100644 --- a/app/cli/lib/context_load.go +++ b/app/cli/lib/context_load.go @@ -12,6 +12,7 @@ import ( "plandex/term" "plandex/types" "plandex/url" + "plandex/utils" "strings" "sync" @@ -87,6 +88,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) { resource = resource[2:] } + resource = utils.EnsureValidPath(resource) inputFilePaths = append(inputFilePaths, resource) } } diff --git a/app/cli/utils/utils.go b/app/cli/utils/utils.go index 346500bb..9e6f1bb1 100644 --- a/app/cli/utils/utils.go +++ b/app/cli/utils/utils.go @@ -10,3 +10,12 @@ func EnsureMinDuration(start time.Time, minDuration time.Duration) { time.Sleep(minDuration - elapsed) } } + +func EnsureValidPath(path string) string { + // Remove trailing slash if it's not the root path + if len(path) > 1 && path[len(path)-1] == '/' { + path = path[:len(path)-1] + } + + return path +} diff --git a/app/cli/utils/utils_test.go b/app/cli/utils/utils_test.go new file mode 100644 index 00000000..a5127f31 --- /dev/null +++ b/app/cli/utils/utils_test.go @@ -0,0 +1,25 @@ +package utils + +import ( + "testing" +) + +func TestEnsureValidPath(t *testing.T) { + tests := []struct { + input string + expected string + }{ + {"/home/user/", "/home/user"}, + {"/", "/"}, + } + + for _, test := range tests { + t.Run("Path: "+test.input, func(t *testing.T) { + output := EnsureValidPath(test.input) + // t.Logf(output) + if output != test.expected { + t.Errorf("EnsureValidPath(%q) = %q; want %q", test.input, output, test.expected) + } + }) + } +}