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
prettying up of load and tell output, other fixes and cleanup
Dane Schneider9689a390eda7
diff --git a/cli/cmd/context_rm.go b/cli/cmd/context_rm.goindex 31919474..1a125cba 100644--- a/cli/cmd/context_rm.go+++ b/cli/cmd/context_rm.go@@ -4,20 +4,38 @@ Copyright Β© 2023 NAME HERE <EMAIL ADDRESS>package cmdimport (+ "log"+ "os"+ "path/filepath"+ "plandex/lib"+"github.com/spf13/cobra")// contextRmCmd represents the delete commandvar contextRmCmd = &cobra.Command{- Use: "rm",- Aliases: []string{"delete"},- Short: "",- Long: ``,- Run: contextRm,+ Use: "rm [indices-or-files-or-urls...]",+ Short: "Remove context by index, filename, or url.",+ Args: cobra.MinimumNArgs(1),+ Run: contextRm,}func contextRm(cmd *cobra.Command, args []string) {+ contextStateFilePath := filepath.Join(lib.ContextSubdir, "context.json")++ contextStateFile, err := os.Open(contextStateFilePath)+ if err != nil {+ log.Fatalf("Error opening file: %v", err)+ }+ defer contextStateFile.Close()++ // var contextState shared.ModelContextState++ // data, err := io.ReadAll(contextStateFile)+ // if err != nil {+ // log.Fatalf("Error reading file: %v", err)+ // }}func init() {diff --git a/cli/cmd/load.go b/cli/cmd/load.goindex fa5812bb..b227e447 100644--- a/cli/cmd/load.go+++ b/cli/cmd/load.go@@ -7,7 +7,14 @@ import ("github.com/spf13/cobra")-var note string+var (+ recursive bool+ maxDepth int+ namesOnly bool+ truncate bool+ maxTokens int+ note string+)var contextLoadCmd = &cobra.Command{Use: "load [files-or-urls...]",@@ -19,8 +26,12 @@ var contextLoadCmd = &cobra.Command{}func init() {- addSharedContextFlags(contextLoadCmd)contextLoadCmd.Flags().StringVarP(¬e, "note", "n", "", "Add a note to the context")+ contextLoadCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Search directories recursively")+ contextLoadCmd.Flags().IntVarP(&maxDepth, "depth", "d", -1, "Maximum depth for recursive directory search (-1 means no limit)")+ contextLoadCmd.Flags().BoolVar(&namesOnly, "names", false, "Only process file names")+ contextLoadCmd.Flags().BoolVar(&truncate, "truncate", false, "Truncate contents if tokens exceed maximum")+ contextLoadCmd.Flags().IntVar(&maxTokens, "max", -1, "Maximum limit for number of tokens")// can be called via plandex load or plandex context loadRootCmd.AddCommand(contextLoadCmd)diff --git a/cli/cmd/shared_context_flags.go b/cli/cmd/shared_context_flags.godeleted file mode 100644index 440b63dc..00000000--- a/cli/cmd/shared_context_flags.go+++ /dev/null@@ -1,22 +0,0 @@-package cmd--import (- "github.com/spf13/cobra"-)--var (- recursive bool- maxDepth int- namesOnly bool- truncate bool- maxTokens int-)--func addSharedContextFlags(cmd *cobra.Command) {-- cmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Search directories recursively")- cmd.Flags().IntVarP(&maxDepth, "depth", "d", -1, "Maximum depth for recursive directory search (-1 means no limit)")- cmd.Flags().BoolVar(&namesOnly, "names", false, "Only process file names")- cmd.Flags().BoolVar(&truncate, "truncate", false, "Truncate contents if tokens exceed maximum")- cmd.Flags().IntVar(&maxTokens, "max", -1, "Maximum limit for number of tokens")-}diff --git a/cli/cmd/tell.go b/cli/cmd/tell.goindex 449a5836..a6de4476 100644--- a/cli/cmd/tell.go+++ b/cli/cmd/tell.go@@ -9,13 +9,11 @@ import ("os/exec""plandex/lib""strings"- "time"- "github.com/briandowns/spinner""github.com/spf13/cobra")-const defaultEditor = "nano"+const defaultEditor = "vim"var promptFile string@@ -103,19 +101,6 @@ func tell(cmd *cobra.Command, args []string) {return}- if lib.CurrentPlanIsDraft() {- s := spinner.New(spinner.CharSets[33], 100*time.Millisecond)- s.Start()-- summaryResp, err := lib.Api.Summarize(prompt)- if err != nil {- fmt.Fprintln(os.Stderr, "\nError summarizing prompt:", err)- return- }- lib.RenameCurrentDraftPlan(lib.GetFileNameWithoutExt(summaryResp.FileName))- s.Stop()- }-err := lib.Propose(prompt)if err != nil {fmt.Fprintln(os.Stderr, "Prompt error:", err)diff --git a/cli/lib/context_load.go b/cli/lib/context_load.goindex 2e703d82..f7d8b4b9 100644--- a/cli/lib/context_load.go+++ b/cli/lib/context_load.go@@ -21,7 +21,10 @@ import ()func LoadContextOrDie(params *types.LoadContextParams) (int, int) {+ timeStart := time.Now()+s := spinner.New(spinner.CharSets[33], 100*time.Millisecond)+ s.Prefix = "π₯ Loading context... "s.Start()var contextState shared.ModelContextStatecontextStateFilePath := filepath.Join(ContextSubdir, "context.json")@@ -480,7 +483,7 @@ func LoadContextOrDie(params *types.LoadContextParams) (int, int) {}}}- msg += fmt.Sprintf(" into context (%d tokens added, %d tokens total)", tokensAdded, totalTokens)+ msg += fmt.Sprintf(" into context | %d πͺ added | %d πͺ total", tokensAdded, totalTokens)if err != nil {log.Fatalf("Failed to get total tokens: %v", err)@@ -505,7 +508,14 @@ func LoadContextOrDie(params *types.LoadContextParams) (int, int) {log.Fatalf("failed to commit submodule updates in root dir: %s\n", err)}+ elapsed := time.Since(timeStart)++ if elapsed < 700*time.Millisecond {+ time.Sleep(700*time.Millisecond - elapsed)+ }+s.Stop()+ clearCurrentLine()fmt.Fprintln(os.Stderr, "β "+msg)return tokensAdded, totalTokensdiff --git a/cli/lib/plans.go b/cli/lib/plans.goindex d71258eb..e757e4f8 100644--- a/cli/lib/plans.go+++ b/cli/lib/plans.go@@ -79,17 +79,28 @@ func RenameCurrentDraftPlan(name string) error {}if CurrentPlanIsDraft() {+ name, err := DedupPlanName(name)+ if err != nil {+ return fmt.Errorf("failed to deduplicate plan name: %w", err)+ }+oldPath := filepath.Join(PlandexDir, CurrentPlanName)newPath := filepath.Join(PlandexDir, name)- err := os.Rename(oldPath, newPath)+ err = os.Rename(oldPath, newPath)if err != nil {- return err+ return fmt.Errorf("failed to rename plan directory: %w", err)}err = SetCurrentPlan(name)if err != nil {- return err+ return fmt.Errorf("failed to set current plan: %w", err)+ }++ // Fixes current plan paths (CurrentPlanName, CurrentPlanRootDir, etc.)+ err = LoadCurrentPlan()+ if err != nil {+ return fmt.Errorf("failed to load current plan: %w", err)}}diff --git a/cli/lib/proposal.go b/cli/lib/proposal.goindex 19077eca..1b93152a 100644--- a/cli/lib/proposal.go+++ b/cli/lib/proposal.go@@ -9,6 +9,7 @@ import ("plandex/types""time"+ "github.com/fatih/color""github.com/looplab/fsm""github.com/plandex/plandex/shared"@@ -21,11 +22,21 @@ type key struct {func Propose(prompt string) error {var err error- fmt.Println("Sending prompt... ")++ start := time.Now()+s := spinner.New(spinner.CharSets[33], 100*time.Millisecond)+ s.Prefix = "π¬ Sending prompt..."s.Start()- // time.Sleep(500 * time.Millisecond)+ if CurrentPlanIsDraft() {+ summaryResp, err := Api.Summarize(prompt)+ if err != nil {+ fmt.Fprintln(os.Stderr, "\nError summarizing prompt:", err)+ return err+ }+ RenameCurrentDraftPlan(GetFileNameWithoutExt(summaryResp.FileName))+ }timestamp := StringTs()reply := ""@@ -93,7 +104,7 @@ func Propose(prompt string) error {go func() {for range replyUpdateTimer.C {- if terminalHasPendingUpdate {+ if replyStarted && terminalHasPendingUpdate {printReply()terminalHasPendingUpdate = false}@@ -191,9 +202,16 @@ func Propose(prompt string) error {return}} else if !replyStarted {- replyStarted = true+ elapsed := time.Since(start)+ if elapsed < 700*time.Millisecond {+ time.Sleep(700*time.Millisecond - elapsed)+ }+s.Stop()+ clearCurrentLine()alternateScreen()++ replyStarted = true}switch state.Current() {@@ -226,10 +244,12 @@ func Propose(prompt string) error {}if desc.MadePlan && (len(desc.Files) > 0) {- fmt.Println("Writing plan draft:")+ fmt.Println(" " + color.New(color.BgHiBlack, color.FgHiWhite, color.Bold).Sprint(" π ") + color.New(color.BgHiBlack, color.FgHiWhite).Sprint("Building plan: "))for _, filePath := range desc.Files {- fmt.Printf("- %s\n", filePath)+ fmt.Printf(" - %s\n", filePath)}+ fmt.Println()+ fmt.Printf(displayHotkeys() + "\n")} else {filesFinished = true}@@ -256,15 +276,16 @@ func Propose(prompt string) error {files := desc.Files// Clear previous lines- moveUpLines(len(files))+ if filesFinished {+ moveUpLines(len(files))+ } else {+ moveUpLines(len(files) + 4)+ }for _, filePath := range files {- // contextPart, foundContext := contextByFilePath[filePath]- // filePathInPlan := isFilePathInPlan(filePath)numStreamedTokens := numStreamedTokensByPath[filePath]- // added := tokensAddedByFile[filePath]- fmtStr := "- %s | %d tokens"+ fmtStr := " - %s | %d πͺ"fmtArgs := []interface{}{filePath, numStreamedTokens}_, finished := finishedByPath[filePath]@@ -272,12 +293,9 @@ func Propose(prompt string) error {if finished {fmtStr += " | done β "}- // else if added > 0 {- // fmtStr += " / %d estimated"- // fmtArgs = append(fmtArgs, added)- // }clearCurrentLine()+fmt.Printf(fmtStr+"\n", fmtArgs...)}@@ -290,7 +308,11 @@ func Propose(prompt string) error {close(done)}}+ }+ if !filesFinished {+ fmt.Println()+ fmt.Printf(displayHotkeys() + "\n")}}diff --git a/server/model/proposal/lorem_ipsum.go b/server/model/proposal/lorem_ipsum.goindex 0ced5613..314acd09 100644--- a/server/model/proposal/lorem_ipsum.go+++ b/server/model/proposal/lorem_ipsum.go@@ -35,7 +35,7 @@ func applyLoremStyling(paragraphs []string) []string {// Function to stream "lorem ipsum" text sentence by sentence with delayfunc streamLoremIpsum(onStream types.OnStreamFunc) {- paragraphs := []string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}+ paragraphs := []string{lorem.Paragraph(1, 1), lorem.Paragraph(1, 1), lorem.Paragraph(1, 1)}paragraphs = applyLoremStyling(paragraphs)for _, paragraph := range paragraphs {@@ -55,7 +55,6 @@ func streamLoremIpsum(onStream types.OnStreamFunc) {planDescription := &shared.PlanDescription{MadePlan: true,Files: []string{"file1.txt", "file2.txt"},- // HasExec: true,}planDescriptionBytes, _ := json.Marshal(planDescription)planDescriptionJson := string(planDescriptionBytes)@@ -83,7 +82,7 @@ func streamFilesLoremIpsum(onStream types.OnStreamFunc) {wg.Add(1)go func(filePath string) {defer wg.Done()- text := strings.Join([]string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}, "\n\n")+ text := strings.Join([]string{lorem.Paragraph(1, 1), lorem.Paragraph(1, 1), lorem.Paragraph(1, 1)}, "\n\n")streamedFile := shared.StreamedFile{Content: text}fileContent, _ := json.Marshal(streamedFile)