Skip to content

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

added clear command, other tweaks

Dane Schneiderf0415f0a7ba3
diff --git a/cli/cmd/clear.go b/cli/cmd/clear.go
new file mode 100644
index 00000000..14344c5b
--- /dev/null
+++ b/cli/cmd/clear.go
@@ -0,0 +1,57 @@
+package cmd
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "plandex/lib"
+ "plandex/types"
+
+ "github.com/spf13/cobra"
+)
+
+var clearCmd = &cobra.Command{
+ Use: "clear",
+ Short: "Clear all context",
+ Long: `Clear all context.`,
+ Run: clearAllContext,
+}
+
+func clearAllContext(cmd *cobra.Command, args []string) {
+ // clear all files from context dir
+ err := os.RemoveAll(lib.ContextSubdir)
+
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error clearing context:", err)
+ return
+ }
+
+ // create context dir
+ err = os.MkdirAll(lib.ContextSubdir, 0755)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error creating context dir:", err)
+ return
+ }
+
+ contextStateFilePath := filepath.Join(lib.ContextSubdir, "context.json")
+ contextState := types.ModelContextState{NumTokens: 0}
+ bytes, err := json.MarshalIndent(contextState, "", " ")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error marshalling context state:", err)
+ return
+ }
+
+ err = os.WriteFile(contextStateFilePath, bytes, 0644)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error writing context state file:", err)
+ return
+ }
+
+ fmt.Println("✅ All context cleared")
+
+}
+
+func init() {
+ RootCmd.AddCommand(clearCmd)
+}
diff --git a/cli/cmd/preview.go b/cli/cmd/preview.go
index e847c526..7fe8a56b 100644
--- a/cli/cmd/preview.go
+++ b/cli/cmd/preview.go
@@ -56,7 +56,7 @@ func checkout(cmd *cobra.Command, args []string) {
name = lib.CurrentPlanName
}
- branchName := "pdx-" + name
+ branchName := name
currentBranch, err := getCurrentBranch()
if err != nil {
diff --git a/cli/cmd/rm.go b/cli/cmd/rm.go
index 4865e634..1f345d12 100644
--- a/cli/cmd/rm.go
+++ b/cli/cmd/rm.go
@@ -15,8 +15,8 @@ import (
var contextRmCmd = &cobra.Command{
Use: "rm",
Aliases: []string{"remove"},
- Short: "Remove a specific context file",
- Long: `This command allows the user to remove a specific context file by providing the file's index as an argument.`,
+ Short: "Remove context",
+ Long: `Remove context by index, name, file path, or url.`,
Args: cobra.MinimumNArgs(1),
Run: contextRm,
}
@@ -36,7 +36,7 @@ func contextRm(cmd *cobra.Command, args []string) {
for i, part := range context {
path := lib.CreateContextFileName(part.Name, part.Sha)
for _, id := range args {
- if fmt.Sprintf("%d", i) == id || part.FilePath == id || part.Url == id {
+ if fmt.Sprintf("%d", i) == id || part.Name == id || part.FilePath == id || part.Url == id {
toRemovePaths = append(toRemovePaths, path)
toRemoveParts = append(toRemoveParts, part)
break
diff --git a/cli/lib/proposal.go b/cli/lib/proposal.go
index 00649f6b..2fb662d2 100644
--- a/cli/lib/proposal.go
+++ b/cli/lib/proposal.go
@@ -143,7 +143,7 @@ func Propose(prompt string) error {
showUpdatedPlanCmds := func() {
fmt.Println()
- for _, cmd := range []string{"diffs", "preview", "apply"} {
+ for _, cmd := range []string{"apply", "preview", "diffs"} {
clearCurrentLine()
PrintCmds(" ", cmd)
}
diff --git a/cli/lib/term.go b/cli/lib/term.go
index 443c0972..845a1407 100644
--- a/cli/lib/term.go
+++ b/cli/lib/term.go
@@ -15,10 +15,10 @@ var cmdDesc = map[string][2]string{
"tell": {"t", "describe a task, ask a question, or chat"},
"diffs": {"d", "show diffs between plan and project files"},
"preview": {"p", "preview the plan in a branch"},
- "apply": {"a", "apply the plan to your project files"},
+ "apply": {"ap", "apply the plan to your project files"},
"next": {"n", "continue to next step of the plan"},
"status": {"s", "show status of the plan"},
- "rewind": {"r", "rewind the plan to a previous step or state"},
+ "rewind": {"rw", "rewind the plan to a previous step or state"},
}
func PrintCmds(prefix string, cmds ...string) {