Skip to content

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

do plaintext handling of 'diffs' command through the 'git diff' call directly rather than stripping ansi codes

Dane Schneider3ad2ebdb4147
diff --git a/app/cli/api/methods.go b/app/cli/api/methods.go
index 959a9d0a..96dab268 100644
--- a/app/cli/api/methods.go
+++ b/app/cli/api/methods.go
@@ -1079,9 +1079,13 @@ func (a *Api) GetPlanStatus(planId, branch string) (string, *shared.ApiError) {
return string(body), nil
}
-func (a *Api) GetPlanDiffs(planId, branch string) (string, *shared.ApiError) {
+func (a *Api) GetPlanDiffs(planId, branch string, plain bool) (string, *shared.ApiError) {
serverUrl := fmt.Sprintf("%s/plans/%s/%s/diffs", getApiHost(), planId, branch)
+ if plain {
+ serverUrl += "?plain=true"
+ }
+
resp, err := authenticatedFastClient.Get(serverUrl)
if err != nil {
return "", &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error sending request: %v", err)}
@@ -1093,7 +1097,7 @@ func (a *Api) GetPlanDiffs(planId, branch string) (string, *shared.ApiError) {
apiErr := handleApiError(resp, errorBody)
tokenRefreshed, apiErr := refreshTokenIfNeeded(apiErr)
if tokenRefreshed {
- return a.GetPlanDiffs(planId, branch)
+ return a.GetPlanDiffs(planId, branch, plain)
}
return "", apiErr
}
diff --git a/app/cli/cmd/diffs.go b/app/cli/cmd/diffs.go
index 2454c1aa..de95e842 100644
--- a/app/cli/cmd/diffs.go
+++ b/app/cli/cmd/diffs.go
@@ -1,7 +1,6 @@
package cmd
import (
- "regexp"
"fmt"
"plandex/api"
"plandex/auth"
@@ -35,7 +34,7 @@ func diffs(cmd *cobra.Command, args []string) {
term.OutputNoCurrentPlanErrorAndExit()
}
- diffs, err := api.Client.GetPlanDiffs(lib.CurrentPlanId, lib.CurrentBranch)
+ diffs, err := api.Client.GetPlanDiffs(lib.CurrentPlanId, lib.CurrentBranch, plainTextOutput)
if err != nil {
term.OutputErrorAndExit("Error getting plan diffs: %v", err)
@@ -43,14 +42,8 @@ func diffs(cmd *cobra.Command, args []string) {
}
if plainTextOutput {
- fmt.Println(stripANSI(diffs))
+ fmt.Println(diffs)
} else {
term.PageOutput(diffs)
}
}
-
-// stripANSI removes ANSI escape codes from the input string
-func stripANSI(input string) string {
- ansiEscape := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
- return ansiEscape.ReplaceAllString(input, "")
-}
\ No newline at end of file
diff --git a/app/cli/types/api.go b/app/cli/types/api.go
index 313776c5..b788b046 100644
--- a/app/cli/types/api.go
+++ b/app/cli/types/api.go
@@ -68,7 +68,7 @@ type ApiClient interface {
RejectAllChanges(planId, branch string) *shared.ApiError
RejectFile(planId, branch, filePath string) *shared.ApiError
RejectFiles(planId, branch string, paths []string) *shared.ApiError
- GetPlanDiffs(planId, branch string) (string, *shared.ApiError)
+ GetPlanDiffs(planId, branch string, plain bool) (string, *shared.ApiError)
LoadContext(planId, branch string, req shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError)
UpdateContext(planId, branch string, req shared.UpdateContextRequest) (*shared.UpdateContextResponse, *shared.ApiError)
diff --git a/app/server/db/diff_helpers.go b/app/server/db/diff_helpers.go
index bfe9776e..383633ff 100644
--- a/app/server/db/diff_helpers.go
+++ b/app/server/db/diff_helpers.go
@@ -10,7 +10,7 @@ import (
"github.com/plandex/plandex/shared"
)
-func GetPlanDiffs(orgId, planId string) (string, error) {
+func GetPlanDiffs(orgId, planId string, plain bool) (string, error) {
planState, err := GetCurrentPlanState(CurrentPlanStateParams{
OrgId: orgId,
PlanId: planId,
@@ -119,7 +119,11 @@ func GetPlanDiffs(orgId, planId string) (string, error) {
return "", fmt.Errorf("error adding files to git repository for dir: %s, err: %v", tempDirPath, err)
}
- res, err := exec.Command("git", "-C", tempDirPath, "diff", "--cached", "--color=always").CombinedOutput()
+ colorArg := "--color=always"
+ if plain {
+ colorArg = "--no-color"
+ }
+ res, err := exec.Command("git", "-C", tempDirPath, "diff", "--cached", colorArg).CombinedOutput()
if err != nil {
return "", fmt.Errorf("error getting diffs: %v", err)
diff --git a/app/server/handlers/plans_changes.go b/app/server/handlers/plans_changes.go
index 40f7fb03..41bb0b31 100644
--- a/app/server/handlers/plans_changes.go
+++ b/app/server/handlers/plans_changes.go
@@ -428,6 +428,7 @@ func GetPlanDiffsHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
planId := vars["planId"]
branch := vars["branch"]
+ plain := r.URL.Query().Get("plain") == "true"
log.Println("planId: ", planId, "branch: ", branch)
@@ -446,7 +447,7 @@ func GetPlanDiffsHandler(w http.ResponseWriter, r *http.Request) {
}()
}
- diffs, err := db.GetPlanDiffs(auth.OrgId, planId)
+ diffs, err := db.GetPlanDiffs(auth.OrgId, planId, plain)
if err != nil {
log.Printf("Error getting plan diffs: %v\n", err)