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
add project paths to tell request, use .plandexignore, skip ignored files via .plandexignore or .gitignore when loading context without --force flag
Dane Schneideredbfeef90d60
diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.goindex 469f16dd..3ae09b81 100644--- a/app/cli/cmd/continue.go+++ b/app/cli/cmd/continue.go@@ -2,38 +2,34 @@ package cmdimport ("fmt"- "log""os"- "plandex/api""plandex/auth""plandex/lib"- streamtui "plandex/stream_tui"+ "plandex/tell""plandex/term"- "github.com/plandex/plandex/shared""github.com/spf13/cobra")// Variables to be used in the nextCmdconst continuePrompt = "Continue the plan."-var continueBg bool-// nextCmd represents the prompt commandvar nextCmd = &cobra.Command{Use: "continue",Aliases: []string{"c"},Short: "Continue the plan.",- Run: next,+ Run: doContinue,}func init() {RootCmd.AddCommand(nextCmd)- nextCmd.Flags().BoolVar(&continueBg, "bg", false, "Execute autonomously in the background")+ nextCmd.Flags().BoolVar(&tellBg, "bg", false, "Execute autonomously in the background")+ tellCmd.Flags().BoolVar(&tellStep, "step", false, "Pause after a single step or reply")}-func next(cmd *cobra.Command, args []string) {+func doContinue(cmd *cobra.Command, args []string) {if os.Getenv("OPENAI_API_KEY") == "" {term.OutputNoApiKeyMsg()os.Exit(1)@@ -43,74 +39,10 @@ func next(cmd *cobra.Command, args []string) {lib.MustResolveProject()lib.MustCheckOutdatedContextWithOutput()- promptingTrialExceeded := false- if !continueBg {- go func() {- err := streamtui.StartStreamUI()-- if err != nil {- fmt.Fprintln(os.Stderr, "Error starting stream UI:", err)- os.Exit(1)- }-- if !promptingTrialExceeded {- os.Exit(0)- }- }()- }-- var fn func() bool- fn = func() bool {- apiErr := api.Client.TellPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.TellPlanRequest{- Prompt: continuePrompt,- ConnectStream: !continueBg,- ApiKey: os.Getenv("OPENAI_API_KEY"),- }, lib.OnStreamPlan)- if apiErr != nil {- log.Println("Error telling plan:", apiErr)- if apiErr.Type == shared.ApiErrorTypeTrialMessagesExceeded {- promptingTrialExceeded = true- streamtui.Quit()- promptingTrialExceeded = false-- fmt.Fprintf(os.Stderr, "π¨ You've reached the free trial limit of %d messages per plan\n", apiErr.TrialMessagesExceededError.MaxReplies)-- res, err := term.ConfirmYesNo("Upgrade now?")-- if err != nil {- fmt.Fprintln(os.Stderr, "Error prompting upgrade trial:", err)- return false- }-- if res {- err := auth.ConvertTrial()- if err != nil {- fmt.Fprintln(os.Stderr, "Error converting trial:", err)- return false- }- // retry action after converting trial- return fn()- }-- return false- }-- fmt.Fprintln(os.Stderr, "Prompt error:", apiErr.Msg)- return false- }- return true- }-- shouldContinue := fn()- if !shouldContinue {+ if lib.CurrentPlanId == "" {+ fmt.Fprintln(os.Stderr, "No current plan")return}- if tellBg {- fmt.Println("β Prompt sent")- } else {- // Wait for stream UI to quit- select {}- }-+ tell.TellPlan(continuePrompt, tellBg, tellStep)}diff --git a/app/cli/cmd/load.go b/app/cli/cmd/load.goindex ea5fab1f..d8b65408 100644--- a/app/cli/cmd/load.go+++ b/app/cli/cmd/load.go@@ -12,9 +12,10 @@ import ()var (- recursive bool- namesOnly bool- note string+ recursive bool+ namesOnly bool+ note string+ forceSkipIgnore bool)var contextLoadCmd = &cobra.Command{@@ -29,6 +30,7 @@ func init() {contextLoadCmd.Flags().StringVarP(¬e, "note", "n", "", "Add a note to the context")contextLoadCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Search directories recursively")contextLoadCmd.Flags().BoolVar(&namesOnly, "tree", false, "Load directory tree with file names only")+ contextLoadCmd.Flags().BoolVarP(&forceSkipIgnore, "force", "f", false, "Load files even when ignored by .gitignore or .plandexignore")RootCmd.AddCommand(contextLoadCmd)}@@ -42,9 +44,10 @@ func contextLoad(cmd *cobra.Command, args []string) {}lib.MustLoadContext(args, &types.LoadContextParams{- Note: note,- Recursive: recursive,- NamesOnly: namesOnly,+ Note: note,+ Recursive: recursive,+ NamesOnly: namesOnly,+ ForceSkipIgnore: forceSkipIgnore,})term.PrintCmds("", "ls", "tell")diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.goindex f55b93f0..17056f22 100644--- a/app/cli/cmd/tell.go+++ b/app/cli/cmd/tell.go@@ -4,14 +4,12 @@ import ("fmt""os""os/exec"- "plandex/api""plandex/auth""plandex/lib"- streamtui "plandex/stream_tui"+ "plandex/tell""plandex/term""strings"- "github.com/plandex/plandex/shared""github.com/spf13/cobra")@@ -30,7 +28,7 @@ var tellCmd = &cobra.Command{Short: "Send a prompt for the current plan.",// Long: ``,Args: cobra.RangeArgs(0, 1),- Run: tell,+ Run: doTell,}func init() {@@ -41,7 +39,7 @@ func init() {tellCmd.Flags().BoolVar(&tellStep, "step", false, "Pause after a single step or reply")}-func tell(cmd *cobra.Command, args []string) {+func doTell(cmd *cobra.Command, args []string) {if os.Getenv("OPENAI_API_KEY") == "" {term.OutputNoApiKeyMsg()os.Exit(1)@@ -50,6 +48,11 @@ func tell(cmd *cobra.Command, args []string) {auth.MustResolveAuthWithOrg()lib.MustResolveProject()+ if lib.CurrentPlanId == "" {+ fmt.Fprintln(os.Stderr, "No current plan")+ return+ }+var prompt stringif len(args) > 0 {@@ -129,76 +132,7 @@ func tell(cmd *cobra.Command, args []string) {lib.MustCheckOutdatedContextWithOutput()- promptingTrialExceeded := false- if !tellBg {- go func() {- err := streamtui.StartStreamUI()-- if err != nil {- fmt.Fprintln(os.Stderr, "Error starting stream UI:", err)- os.Exit(1)- }-- if !promptingTrialExceeded {- os.Exit(0)- }- }()- }-- var fn func() bool- fn = func() bool {- apiErr := api.Client.TellPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.TellPlanRequest{- Prompt: prompt,- ConnectStream: !tellBg,- AutoContinue: !tellStep,- ApiKey: os.Getenv("OPENAI_API_KEY"),- }, lib.OnStreamPlan)- if apiErr != nil {- if apiErr.Type == shared.ApiErrorTypeTrialMessagesExceeded {- promptingTrialExceeded = true- streamtui.Quit()- promptingTrialExceeded = false-- fmt.Fprintf(os.Stderr, "\nπ¨ You've reached the free trial limit of %d messages per plan\n", apiErr.TrialMessagesExceededError.MaxReplies)-- res, err := term.ConfirmYesNo("Upgrade now?")-- if err != nil {- fmt.Fprintln(os.Stderr, "Error prompting upgrade trial:", err)- return false- }-- if res {- err := auth.ConvertTrial()- if err != nil {- fmt.Fprintln(os.Stderr, "Error converting trial:", err)- return false- }- // retry action after converting trial- return fn()- }- return false- }-- fmt.Fprintln(os.Stderr, "Prompt error:", apiErr.Msg)- return false- }-- return true- }-- shouldContinue := fn()- if !shouldContinue {- return- }-- if tellBg {- fmt.Println("β Prompt sent")- } else {- // Wait for stream UI to quit- select {}- }-+ tell.TellPlan(prompt, tellBg, tellStep)}func prepareEditorCommand(editor string, filename string) *exec.Cmd {diff --git a/app/cli/fs/fs.go b/app/cli/fs/fs.goindex c76efe67..4b7da769 100644--- a/app/cli/fs/fs.go+++ b/app/cli/fs/fs.go@@ -1,8 +1,13 @@package fsimport (+ "fmt""os"+ "os/exec""path/filepath"+ "strings"++ ignore "github.com/sabhiram/go-gitignore")var Cwd string@@ -62,6 +67,135 @@ func FindOrCreatePlandex() (string, bool, error) {return dir, true, nil}+func ProjectRootIsGitRepo() bool {+ if ProjectRoot == "" {+ return false+ }++ return IsGitRepo(ProjectRoot)+}++func IsGitRepo(dir string) bool {+ isGitRepo := false++ if isCommandAvailable("git") {+ // check whether we're in a git repo+ cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree")++ cmd.Dir = dir++ err := cmd.Run()++ if err == nil {+ isGitRepo = true+ }+ }++ return isGitRepo+}++func GetProjectPaths() (map[string]bool, *ignore.GitIgnore, error) {+ if ProjectRoot == "" {+ return nil, nil, fmt.Errorf("no project root found")+ }++ return GetPaths(ProjectRoot)+}++func GetPaths(dir string) (map[string]bool, *ignore.GitIgnore, error) {+ paths := map[string]bool{}++ if ProjectRootIsGitRepo() {+ // combine `git ls-files` and `git ls-files --others --exclude-standard`+ // to get all files in the repo++ // get all tracked files in the repo+ cmd := exec.Command("git", "ls-files")+ cmd.Dir = dir+ out, err := cmd.Output()++ if err != nil {+ return nil, nil, fmt.Errorf("error getting files in git repo: %s", err)+ }++ files := strings.Split(string(out), "\n")++ for _, file := range files {+ paths[file] = true+ }++ // get all untracked files non-ignored files in the repo+ cmd = exec.Command("git", "ls-files", "--others", "--exclude-standard")+ cmd.Dir = dir+ out, err = cmd.Output()++ if err != nil {+ return nil, nil, fmt.Errorf("error getting untracked files in git repo: %s", err)+ }++ files = strings.Split(string(out), "\n")++ for _, file := range files {+ paths[file] = true+ }+ } else {+ // get all files in the directory+ err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {+ if err != nil {+ return err+ }++ if !info.IsDir() {+ relPath, err := filepath.Rel(dir, path)+ if err != nil {+ return err+ }+ paths[relPath] = true+ }++ return nil+ })++ if err != nil {+ return nil, nil, fmt.Errorf("error getting files in directory: %s", err)+ }+ }++ ignored, err := GetPlandexIgnore()++ if err != nil {+ return nil, nil, err+ }++ if ignored != nil {+ for path := range paths {+ if ignored.MatchesPath(path) {+ delete(paths, path)+ }+ }+ }++ return paths, ignored, nil+}++func GetPlandexIgnore() (*ignore.GitIgnore, error) {+ ignorePath := filepath.Join(ProjectRoot, ".plandexignore")++ if _, err := os.Stat(ignorePath); err == nil {+ ignored, err := ignore.CompileIgnoreFile(ignorePath)++ if err != nil {+ return nil, fmt.Errorf("error reading .plandexignore file: %s", err)+ }++ return ignored, nil+ } else if !os.IsNotExist(err) {+ return nil, fmt.Errorf("error checking for .plandexignore file: %s", err)+ }++ return nil, nil+}+func findPlandex() (string, string) {searchPath := Cwdfor searchPath != "/" {@@ -74,3 +208,11 @@ func findPlandex() (string, string) {return "", ""}++func isCommandAvailable(name string) bool {+ cmd := exec.Command(name, "--version")+ if err := cmd.Run(); err != nil {+ return false+ }+ return true+}diff --git a/app/cli/go.mod b/app/cli/go.modindex e6d99ce3..f65388e3 100644--- a/app/cli/go.mod+++ b/app/cli/go.mod@@ -55,6 +55,7 @@ require (github.com/mattn/go-runewidth v0.0.15 // indirectgithub.com/pkoukk/tiktoken-go v0.1.6 // indirectgithub.com/plandex/plandex/shared v0.0.0-00010101000000-000000000000+ github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06github.com/spf13/pflag v1.0.5 // indirectgolang.org/x/text v0.14.0 // indirect)diff --git a/app/cli/go.sum b/app/cli/go.sumindex 80d6bf35..710ca655 100644--- a/app/cli/go.sum+++ b/app/cli/go.sum@@ -630,6 +630,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDgithub.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94/go.mod h1:b18R55ulyQ/h3RaWyloPyER7fWQVZvimKKhnI5OfrJQ=+github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=+github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=github.com/sagikazarmark/crypt v0.8.0/go.mod h1:TmKwZAo97S4Fy4sfMH/HX/cQP5D+ijra2NyLpNNmttY=github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.goindex e0816e0a..1ad2adc7 100644--- a/app/cli/lib/apply.go+++ b/app/cli/lib/apply.go@@ -217,7 +217,7 @@ func ApplyPlanWithOutput(planId, branch string, autoConfirm bool) error {return nil}- isRepo := CwdIsGitRepo()+ isRepo := fs.ProjectRootIsGitRepo()hasUncommittedChanges := falseif isRepo {diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex be3e6421..f5c9b426 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -6,16 +6,17 @@ import ("io""os""plandex/api"+ "plandex/fs""plandex/term""plandex/types""plandex/url""strings""github.com/plandex/plandex/shared"+ ignore "github.com/sabhiram/go-gitignore")func MustLoadContext(resources []string, params *types.LoadContextParams) {-term.StartSpinner("π₯ Loading context...")onErr := func(err error) {@@ -68,7 +69,33 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {contextCh := make(chan *shared.LoadContextParams)errCh := make(chan error)+ ignoredPaths := make(map[string]string)+if len(inputFilePaths) > 0 {++ projectPaths := make(map[string]bool)+ var plandexIgnored *ignore.GitIgnore++ if !params.ForceSkipIgnore {+ projectPaths, plandexIgnored, err = fs.GetProjectPaths()+ if err != nil {+ onErr(fmt.Errorf("failed to get project paths: %v", err))+ }+ var filteredPaths []string+ for _, inputFilePath := range inputFilePaths {+ if _, ok := projectPaths[inputFilePath]; !ok {+ if plandexIgnored.MatchesPath(inputFilePath) {+ ignoredPaths[inputFilePath] = "plandex"+ } else {+ ignoredPaths[inputFilePath] = "git"+ }+ } else {+ filteredPaths = append(filteredPaths, inputFilePath)+ }+ }+ inputFilePaths = filteredPaths+ }+if params.NamesOnly {for _, inputFilePath := range inputFilePaths {@@ -79,6 +106,20 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {return}+ if !params.ForceSkipIgnore {+ var filteredPaths []string+ for _, path := range flattenedPaths {+ if _, ok := projectPaths[path]; ok {+ filteredPaths = append(filteredPaths, path)+ } else if plandexIgnored != nil && plandexIgnored.MatchesPath(path) {+ ignoredPaths[path] = "plandex"+ } else {+ ignoredPaths[path] = "git"+ }+ }+ flattenedPaths = filteredPaths+ }+body := strings.Join(flattenedPaths, "\n")name := inputFilePath@@ -104,7 +145,22 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {onErr(fmt.Errorf("failed to parse input paths: %v", err))}+ if !params.ForceSkipIgnore {+ var filteredPaths []string+ for _, path := range flattenedPaths {+ if _, ok := projectPaths[path]; ok {+ filteredPaths = append(filteredPaths, path)+ } else if plandexIgnored != nil && plandexIgnored.MatchesPath(path) {+ ignoredPaths[path] = "plandex"+ } else {+ ignoredPaths[path] = "git"+ }+ }+ flattenedPaths = filteredPaths+ }+inputFilePaths = flattenedPaths+for _, path := range flattenedPaths {go func(path string) {@@ -121,12 +177,9 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {Body: body,FilePath: path,}-}(path)-}}-}if len(inputUrls) > 0 {@@ -184,4 +237,10 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {}fmt.Println("β " + res.Msg)++ if len(ignoredPaths) > 0 {+ fmt.Println()+ fmt.Println("βΉοΈ Due to .gitignore or .plandexignore, some paths weren't loaded. Use --force / -f to load ignored paths.")++ }}diff --git a/app/cli/lib/git.go b/app/cli/lib/git.goindex 897a6439..2422b994 100644--- a/app/cli/lib/git.go+++ b/app/cli/lib/git.go@@ -10,18 +10,6 @@ import (var gitMutex sync.Mutex-func InitGitRepo(dir string) error {- gitMutex.Lock()- defer gitMutex.Unlock()-- res, err := exec.Command("git", "init", dir).CombinedOutput()- if err != nil {- return fmt.Errorf("error initializing git repository for dir: %s, err: %v, output: %s", dir, err, string(res))- }-- return GitAddAndCommit(dir, "New plan", false)-}-func GitAddAndCommit(dir, message string, lockMutex bool) error {if lockMutex {gitMutex.Lock()@@ -157,19 +145,6 @@ func parseConflictFiles(gitOutput string) []string {return conflictFiles}-func CwdIsGitRepo() bool {- isGitRepo := false- if IsCommandAvailable("git") {- // check whether we're in a git repo- _, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()- if err == nil {- isGitRepo = true- }- }-- return isGitRepo-}-func GitClearUncommittedChanges() error {gitMutex.Lock()defer gitMutex.Unlock()diff --git a/app/cli/lib/os.go b/app/cli/lib/os.godeleted file mode 100644index bc1d9f98..00000000--- a/app/cli/lib/os.go+++ /dev/null@@ -1,11 +0,0 @@-package lib--import "os/exec"--func IsCommandAvailable(name string) bool {- cmd := exec.Command(name, "--version")- if err := cmd.Run(); err != nil {- return false- }- return true-}diff --git a/app/cli/tell/tell.go b/app/cli/tell/tell.gonew file mode 100644index 00000000..9be53a29--- /dev/null+++ b/app/cli/tell/tell.go@@ -0,0 +1,94 @@+package tell++import (+ "fmt"+ "os"+ "plandex/api"+ "plandex/auth"+ "plandex/fs"+ "plandex/lib"+ streamtui "plandex/stream_tui"+ "plandex/term"++ "github.com/plandex/plandex/shared"+)++func TellPlan(prompt string, tellBg, tellStep bool) {+ projectPaths, _, err := fs.GetProjectPaths()++ if err != nil {+ fmt.Fprintln(os.Stderr, "Error getting project paths:", err)+ return+ }++ promptingTrialExceeded := false+ var fn func() bool+ fn = func() bool {+ if !tellBg {+ go func() {+ err := streamtui.StartStreamUI()++ if err != nil {+ fmt.Fprintln(os.Stderr, "Error starting stream UI:", err)+ os.Exit(1)+ }++ if !promptingTrialExceeded {+ os.Exit(0)+ }+ }()+ }++ apiErr := api.Client.TellPlan(lib.CurrentPlanId, lib.CurrentBranch, shared.TellPlanRequest{+ Prompt: prompt,+ ConnectStream: !tellBg,+ AutoContinue: !tellStep,+ ProjectPaths: projectPaths,+ ApiKey: os.Getenv("OPENAI_API_KEY"),+ }, lib.OnStreamPlan)+ if apiErr != nil {+ if apiErr.Type == shared.ApiErrorTypeTrialMessagesExceeded {+ promptingTrialExceeded = true+ streamtui.Quit()+ promptingTrialExceeded = false++ fmt.Fprintf(os.Stderr, "\nπ¨ You've reached the free trial limit of %d messages per plan\n", apiErr.TrialMessagesExceededError.MaxReplies)++ res, err := term.ConfirmYesNo("Upgrade now?")++ if err != nil {+ fmt.Fprintln(os.Stderr, "Error prompting upgrade trial:", err)+ return false+ }++ if res {+ err := auth.ConvertTrial()+ if err != nil {+ fmt.Fprintln(os.Stderr, "Error converting trial:", err)+ return false+ }+ // retry action after converting trial+ return fn()+ }+ return false+ }++ fmt.Fprintln(os.Stderr, "Prompt error:", apiErr.Msg)+ return false+ }++ return true+ }++ shouldContinue := fn()+ if !shouldContinue {+ return+ }++ if tellBg {+ fmt.Println("β Prompt sent")+ } else {+ // Wait for stream UI to quit+ select {}+ }+}diff --git a/app/cli/types/types.go b/app/cli/types/types.goindex f27a87a2..bf530029 100644--- a/app/cli/types/types.go+++ b/app/cli/types/types.go@@ -19,9 +19,10 @@ type ClientAuth struct {}type LoadContextParams struct {- Note string- Recursive bool- NamesOnly bool+ Note string+ Recursive bool+ NamesOnly bool+ ForceSkipIgnore bool}type ContextOutdatedResult struct {diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex 04edd914..97e4e127 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -90,10 +90,11 @@ type GetCurrentBranchByPlanIdRequest struct {}type TellPlanRequest struct {- Prompt string `json:"prompt"`- ConnectStream bool `json:"connectStream"`- AutoContinue bool `json:"autoContinue"`- ApiKey string `json:"apiKey"`+ Prompt string `json:"prompt"`+ ConnectStream bool `json:"connectStream"`+ AutoContinue bool `json:"autoContinue"`+ ApiKey string `json:"apiKey"`+ ProjectPaths map[string]bool `json:"projectPaths"`}type LoadContextParams struct {