Skip to content

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

buncha fixes and improvements

Dane Schneiderb5f9df669b04
diff --git a/cli/cmd/apply.go b/cli/cmd/apply.go
index 6b4e58aa..64a8a609 100644
--- a/cli/cmd/apply.go
+++ b/cli/cmd/apply.go
@@ -17,15 +17,20 @@ func init() {
}
var applyCmd = &cobra.Command{
- Use: "apply [name]",
- Short: "Apply a plan to the project",
- Args: cobra.MaximumNArgs(1),
- RunE: apply,
+ Use: "apply [name]",
+ Aliases: []string{"ap"},
+ Short: "Apply a plan to the project",
+ Args: cobra.MaximumNArgs(1),
+ RunE: apply,
}
func apply(cmd *cobra.Command, args []string) error {
plandexDir, _, err := lib.FindOrCreatePlandex()
- name := args[0]
+ var name string
+
+ if len(args) > 0 {
+ name = args[0]
+ }
if err != nil {
return fmt.Errorf("Error: %v", err)
@@ -36,7 +41,7 @@ func apply(cmd *cobra.Command, args []string) error {
}
if name == "" {
- log.Fatalln("No plan name provided and no current plan is set.")
+ log.Fatalf("No plan name provided. Use 'plandex apply current' to apply the current plan: %s\n", lib.CurrentPlanName)
}
// Check git installed
diff --git a/cli/cmd/context_ls.go b/cli/cmd/context_ls.go
index 096cdbc6..a1b12c79 100644
--- a/cli/cmd/context_ls.go
+++ b/cli/cmd/context_ls.go
@@ -28,7 +28,11 @@ func contextLs(cmd *cobra.Command, args []string) {
os.Exit(1)
}
+ totalTokens := 0
+
for i, part := range context {
+ totalTokens += part.NumTokens
+
if i != 0 {
fmt.Print("\n\n")
}
@@ -48,6 +52,9 @@ func contextLs(cmd *cobra.Command, args []string) {
fmt.Printf("Summary:\n%s", part.Summary)
}
+
+ fmt.Printf("\n\nTotal tokens: %d\n", totalTokens)
+
}
func init() {
diff --git a/cli/cmd/load.go b/cli/cmd/load.go
index 4d063ae6..7a613c23 100644
--- a/cli/cmd/load.go
+++ b/cli/cmd/load.go
@@ -13,7 +13,7 @@ var contextLoadCmd = &cobra.Command{
Use: "load [files-or-urls...]",
Short: "Load context from various inputs",
Long: `Load context from a file path, a directory, a URL, text, or piped data.`,
- Args: cobra.RangeArgs(0, 1),
+ Args: cobra.MinimumNArgs(1),
Run: contextLoad,
}
diff --git a/cli/cmd/checkout.go b/cli/cmd/preview.go
similarity index 72%
rename from cli/cmd/checkout.go
rename to cli/cmd/preview.go
index f7285fcd..bcb563ae 100644
--- a/cli/cmd/checkout.go
+++ b/cli/cmd/preview.go
@@ -16,10 +16,11 @@ func init() {
}
var checkoutCmd = &cobra.Command{
- Use: "checkout [name]",
- Short: "Checkout to a new branch and apply a plan",
- Args: cobra.ExactArgs(1),
- Run: checkout,
+ Use: "preview [name]",
+ Aliases: []string{"pv"},
+ Short: "Preview changes in a new branch",
+ Args: cobra.MaximumNArgs(1),
+ Run: checkout,
}
func checkout(cmd *cobra.Command, args []string) {
@@ -32,6 +33,14 @@ func checkout(cmd *cobra.Command, args []string) {
log.Fatalln("Error: please make sure you're inside of a git repository")
}
+ if name == "current" {
+ name = lib.CurrentPlanName
+ }
+
+ if name == "" {
+ log.Fatalf("No plan name provided. Use 'plandex preview current' to preview the current plan in a branch: %s\n", lib.CurrentPlanName)
+ }
+
branchName := "pdx_" + args[0]
_, err = exec.Command("git", "checkout", "-b", branchName).CombinedOutput()
diff --git a/cli/cmd/shared_context_flags.go b/cli/cmd/shared_context_flags.go
index 5c1ce1d5..8067edd8 100644
--- a/cli/cmd/shared_context_flags.go
+++ b/cli/cmd/shared_context_flags.go
@@ -11,14 +11,14 @@ var (
maxDepth int16
namesOnly bool
truncate bool
- maxTokens uint32 = shared.MaxTokens
+ maxTokens int = shared.MaxTokens
)
func addSharedContextFlags(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Search directories recursively")
- cmd.Flags().Int16VarP(&maxDepth, "max-depth", "d", -1, "Maximum depth for recursive directory search (-1 means no limit)")
- cmd.Flags().BoolVar(&namesOnly, "names-only", false, "Only process file names")
- cmd.Flags().BoolVar(&truncate, "truncate", false, "Truncate contents if tokens exceed maximum, otherwise abort")
- cmd.Flags().Uint32Var(&maxTokens, "max-tokens", shared.MaxTokens, "Maximum limit for number of tokens")
+ cmd.Flags().Int16VarP(&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", shared.MaxTokens, "Maximum limit for number of tokens")
}
diff --git a/cli/lib/context.go b/cli/lib/context.go
index 16a8f2b5..d91600bb 100644
--- a/cli/lib/context.go
+++ b/cli/lib/context.go
@@ -70,6 +70,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
}
}()
+ tokensAdded := 0
totalTokens := contextState.NumTokens
var totalTokensMutex sync.Mutex
@@ -94,6 +95,8 @@ func LoadContextOrDie(params *types.LoadContextParams) {
defer totalTokensMutex.Unlock()
totalTokens += numTokens
+ tokensAdded += numTokens
+
if totalTokens > params.MaxTokens {
if params.Truncate {
log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d). Truncating input text.", totalTokens, params.MaxTokens)
@@ -170,6 +173,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
defer totalTokensMutex.Unlock()
totalTokens += numTokens
+ tokensAdded += numTokens
if totalTokens > params.MaxTokens {
if params.Truncate {
log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d). Truncating piped data.", totalTokens, params.MaxTokens)
@@ -241,6 +245,9 @@ func LoadContextOrDie(params *types.LoadContextParams) {
if params.NamesOnly {
body := strings.Join(flattenedPaths, "\n")
bytes := []byte(body)
+
+ fmt.Println(body)
+
hash := sha256.Sum256(bytes)
sha := hex.EncodeToString(hash[:])
numTokens := shared.GetNumTokens(body)
@@ -249,6 +256,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
func() {
defer totalTokensMutex.Unlock()
totalTokens += numTokens
+ tokensAdded += numTokens
if totalTokens > params.MaxTokens {
if params.Truncate {
@@ -307,6 +315,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
func() {
defer totalTokensMutex.Unlock()
totalTokens += numTokens
+ tokensAdded += numTokens
if totalTokens > params.MaxTokens {
if params.Truncate {
@@ -378,6 +387,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
func() {
defer totalTokensMutex.Unlock()
totalTokens += numTokens
+ tokensAdded += numTokens
if totalTokens > params.MaxTokens {
if params.Truncate {
log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d). Truncating content from URL %s.", totalTokens, params.MaxTokens, url)
@@ -465,10 +475,18 @@ func LoadContextOrDie(params *types.LoadContextParams) {
added = append(added, "piped data")
}
if len(inputFilePaths) > 0 {
- added = append(added, fmt.Sprintf("%d files", len(inputFilePaths)))
+ label := "file"
+ if len(inputFilePaths) > 1 {
+ label = "files"
+ }
+ added = append(added, fmt.Sprintf("%d %s", len(inputFilePaths), label))
}
if len(inputUrls) > 0 {
- added = append(added, fmt.Sprintf("%d urls", len(inputUrls)))
+ label := "url"
+ if len(inputUrls) > 1 {
+ label = "urls"
+ }
+ added = append(added, fmt.Sprintf("%d %s", len(inputUrls), label))
}
msg := "Loaded "
@@ -483,7 +501,13 @@ func LoadContextOrDie(params *types.LoadContextParams) {
}
}
}
- msg += " into context"
+ msg += fmt.Sprintf(" into context (%d tokens)", tokensAdded)
+
+ if err != nil {
+ log.Fatalf("Failed to get total tokens: %v", err)
+ }
+
+ msg += fmt.Sprintf("\n\nTotal tokens in context: %d\n", totalTokens)
err = GitAddAndCommit(ContextSubdir, msg)
@@ -503,7 +527,7 @@ func LoadContextOrDie(params *types.LoadContextParams) {
fmt.Printf("failed to commit submodule updates in root dir: %s\n", err)
}
- fmt.Fprint(os.Stderr, msg)
+ fmt.Fprint(os.Stderr, "✅ "+msg+"\n")
}
func GetAllContext(metaOnly bool) ([]shared.ModelContextPart, error) {
diff --git a/cli/lib/fs.go b/cli/lib/fs.go
index fbca52a6..8a3119f7 100644
--- a/cli/lib/fs.go
+++ b/cli/lib/fs.go
@@ -165,6 +165,9 @@ func FlattenPaths(fileOrDirPaths []string, params *types.LoadContextParams, dept
}
if info.IsDir() {
+ if info.Name() == ".git" || info.Name() == ".plandex" {
+ return filepath.SkipDir
+ }
if depth < params.MaxDepth {
for _, subPath := range FlattenPaths([]string{path}, params, depth+1) {
resPathsChan <- subPath
diff --git a/cli/lib/plan.go b/cli/lib/plan.go
index 89c591aa..ec260bba 100644
--- a/cli/lib/plan.go
+++ b/cli/lib/plan.go
@@ -73,21 +73,47 @@ func getCurrentPlanFiles() (shared.CurrentPlanFiles, error) {
}
}
- // var execContent string
- // var execExists bool
- // execPath := filepath.Join(CurrentPlanRootDir, "exec.sh")
- // _, err = os.Stat(execPath)
- // execExists = !os.IsNotExist(err)
-
- // if execExists {
- // // exec.sh exists
- // // Read file content and set it to planFiles["exec"]
- // content, err := os.ReadFile(execPath)
- // if err != nil {
- // return shared.CurrentPlanFiles{}, err
- // }
- // execContent = string(content)
- // }
-
- return shared.CurrentPlanFiles{Files: planFiles.data /*Exec: execContent*/}, nil
+ return shared.CurrentPlanFiles{Files: planFiles.data}, nil
+}
+
+func getCurrentPlanFilePaths() ([]string, error) {
+ // Check if filesDir exists
+ _, err := os.Stat(PlanFilesDir)
+ exists := !os.IsNotExist(err)
+
+ filePaths := make([]string, 0)
+
+ if exists {
+ // Enumerate all paths in [planDir]/files
+ err = filepath.Walk(PlanFilesDir, func(srcPath string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ filePaths = append(filePaths, srcPath)
+ return nil
+ })
+
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error listing files: %v", err)
+ return []string{}, err
+ }
+ }
+
+ return filePaths, nil
+}
+
+func isFilePathInPlan(filePath string) bool {
+ filePaths, err := getCurrentPlanFilePaths()
+ if err != nil {
+ return false
+ }
+
+ for _, path := range filePaths {
+ if path == filePath {
+ return true
+ }
+ }
+
+ return false
}
diff --git a/cli/lib/proposal.go b/cli/lib/proposal.go
index a35d1b4c..4c8c9578 100644
--- a/cli/lib/proposal.go
+++ b/cli/lib/proposal.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "path/filepath"
"plandex/types"
"time"
@@ -52,6 +53,21 @@ func Propose(prompt string) error {
replyTokenCounter := shared.NewReplyInfo(true)
var tokensAddedByFile map[string]int
+ currentPlanTokensByFilePath := make(map[string]int)
+ currrentPlanTokensPath := filepath.Join(CurrentPlanRootDir, "tokens.json")
+ if _, err := os.Stat(currrentPlanTokensPath); os.IsNotExist(err) {
+ currentPlanTokensByFilePath = make(map[string]int)
+ } else {
+ fileBytes, err := os.ReadFile(currrentPlanTokensPath)
+ if err != nil {
+ return fmt.Errorf("failed to open current plan token count file: %s\n", err)
+ }
+ err = json.Unmarshal(fileBytes, &currentPlanTokensByFilePath)
+ if err != nil {
+ return fmt.Errorf("failed to parse current plan token count json: %s\n", err)
+ }
+ }
+
printReply := func() {
clearScreen()
moveCursorToTopLeft()
@@ -77,7 +93,7 @@ func Propose(prompt string) error {
endReply := func() {
replyUpdateTimer.Stop()
-
+ printReply()
backToMain()
fmt.Print(termState)
err := appendConversation(timestamp, prompt, reply)
@@ -207,6 +223,7 @@ func Propose(prompt string) error {
for _, filePath := range files {
contextPart, foundContext := contextByFilePath[filePath]
+ filePathInPlan := isFilePathInPlan(filePath)
contextTokens := contextTokensByFile[filePath]
added := tokensAddedByFile[filePath]
@@ -218,7 +235,12 @@ func Propose(prompt string) error {
if finished {
fmtStr += " | done ✅"
} else {
- if foundContext {
+ if filePathInPlan {
+ fmtStr += " / %d estimated (%d base + ~%d changes)"
+ currentTotal := currentPlanTokensByFilePath[filePath]
+ total := currentTotal + added
+ fmtArgs = append(fmtArgs, total, currentTotal, added)
+ } else if foundContext {
fmtStr += " / %d estimated (%d base + ~%d changes)"
contextTotal := int(contextPart.NumTokens)
total := contextTotal + added
diff --git a/cli/lib/stream.go b/cli/lib/stream.go
index 9b03ca21..125413f6 100644
--- a/cli/lib/stream.go
+++ b/cli/lib/stream.go
@@ -54,6 +54,42 @@ func receiveFileChunk(content string, desc *shared.PlanDescription, jsonBuffers
return false, fmt.Errorf("failed to write plan file '%s': %v\n", filePath, err)
}
+ currentPlanTokensByFilePath := make(map[string]int)
+ currrentPlanTokensPath := filepath.Join(CurrentPlanRootDir, "tokens.json")
+
+ // Read the existing token counts if the file exists.
+ if _, err := os.Stat(currrentPlanTokensPath); !os.IsNotExist(err) {
+ fileBytes, err := os.ReadFile(currrentPlanTokensPath)
+ if err != nil {
+ return false, fmt.Errorf("failed to read current plan token count file: %s", err)
+ }
+ err = json.Unmarshal(fileBytes, &currentPlanTokensByFilePath)
+ if err != nil {
+ return false, fmt.Errorf("failed to parse current plan token count json: %s", err)
+ }
+ }
+
+ // Update token count for this file.
+ currentPlanTokensByFilePath[chunk.FilePath] = numTokensByFile[chunk.FilePath]
+
+ // Write the updated token counts.
+ tokensFileBytes, err := json.Marshal(currentPlanTokensByFilePath)
+ if err != nil {
+ return false, fmt.Errorf("failed to marshal current plan token count json: %s", err)
+ }
+
+ // Open the file for writing with truncation.
+ tokensFile, err := os.OpenFile(currrentPlanTokensPath, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
+ if err != nil {
+ return false, fmt.Errorf("failed to open current plan token count file for writing: %s", err)
+ }
+ defer tokensFile.Close()
+
+ _, err = tokensFile.Write(tokensFileBytes)
+ if err != nil {
+ return false, fmt.Errorf("failed to write current plan token count file: %s", err)
+ }
+
// fmt.Println("Wrote to file " + filePath)
finishedByFile[chunk.FilePath] = true
diff --git a/cli/lib/term.go b/cli/lib/term.go
index 4235cfd1..569a3378 100644
--- a/cli/lib/term.go
+++ b/cli/lib/term.go
@@ -65,7 +65,7 @@ func handleReviseKey(proposalId string) error {
func handleKeyPress(input rune, proposalId string) error {
switch input {
- case 'a':
+ case 's':
return handleAbortKey(proposalId)
case 'r':
return handleReviseKey(proposalId)
@@ -93,6 +93,6 @@ func displayHotkeys() string {
divisionLine := strings.Repeat("─", terminalWidth)
return divisionLine + "\n" +
- " \x1b[1m(a)\x1b[0m" + `bort ` + "\x1b[1m(r)\x1b[0m" + `evise
+ " \x1b[1m(s)\x1b[0m" + `top
` + divisionLine
}
diff --git a/cli/types/types.go b/cli/types/types.go
index 82ad86b5..508ebf85 100644
--- a/cli/types/types.go
+++ b/cli/types/types.go
@@ -7,7 +7,7 @@ import (
type LoadContextParams struct {
Note string
- MaxTokens uint32
+ MaxTokens int
Recursive bool
MaxDepth int16
NamesOnly bool
diff --git a/server/model/proposal/confirm.go b/server/model/proposal/confirm.go
index 73d9b9a3..75d1766e 100644
--- a/server/model/proposal/confirm.go
+++ b/server/model/proposal/confirm.go
@@ -60,18 +60,32 @@ func confirmProposal(proposalId string, onStream types.OnStreamFunc) error {
// get relevant file context (if any)
var fileContext *shared.ModelContextPart
- for _, part := range *proposal.ModelContext {
+ for _, part := range proposal.Request.ModelContext {
if part.FilePath == filePath {
fileContext = &part
break
}
}
- fileMessages := []openai.ChatCompletionMessage{}
+ fmtStr := ""
+ fmtArgs := []interface{}{}
+
if fileContext != nil {
+ fmtStr += "Original file %s:\n```\n%s\n```"
+ fmtArgs = []interface{}{filePath, fileContext.Body}
+ }
+
+ currentState := proposal.Request.CurrentPlan.Files[filePath]
+ if currentState != "" {
+ fmtStr += "\nCurrent state of file %s in the plan:\n```\n%s\n```"
+ fmtArgs = append(fmtArgs, filePath, currentState)
+ }
+
+ fileMessages := []openai.ChatCompletionMessage{}
+ if fileContext != nil || currentState != "" {
fileMessages = append(fileMessages, openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleSystem,
- Content: fmt.Sprintf("Original file %s:\n```\n%s\n```", filePath, fileContext.Body),
+ Content: fmt.Sprintf(fmtStr, fmtArgs...),
})
}
diff --git a/server/model/proposal/create.go b/server/model/proposal/create.go
index 647d1d5d..44e484dc 100644
--- a/server/model/proposal/create.go
+++ b/server/model/proposal/create.go
@@ -28,18 +28,21 @@ const systemMessageHead = `
- Ask the user for more information or context and stop there.
2. Decide whether this task is small enough to be completed in a single response.
- a. If so, write out the code to complete the task. Precede the code with the file path like this '- file_path:'.
+ a. If so, write out the code to complete the task. Precede the code with the file path like this '- file_path:'--for example:
+ - src/main.rs:
+ - lib/utils.go:
+ - main.py:
b. If not:
- Explicitly say "I will break this large task into subtasks."
- Divide the task into smaller subtasks and list them in a numbered list. Stop there.
- Always precede code blocks them with the file path like this '- file_path:'.
+ Always precede code blocks the file path as described above in 2a. Code must *always* be labelled with the path. You can have multiple code blocks labelled with the same file path.
- Code should always be inside a file block labelled with the path. You can have multiple blocks labelled with the same file path. Every file you reference should either exist in the context directly or be a new file that will be created in the same base directory as the context file paths.
+ Every file you reference should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/utils.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/utils.go'.
For code in markdown blocks, always include the language name after the opening triple backticks.
- Don't include unnecessary comments in code. Only add comments if they make the code significantly more readable. Make comments concise.
+ Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user.
At the end of a plan, you can suggest additional iterations to make the plan better. You can also ask the user to load more files or information into context if it would help you make a better plan.
@@ -93,9 +96,9 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) error
// store the proposal
proposals.Set(proposalId, &types.Proposal{
- Id: proposalId,
- ModelContext: &req.ModelContext,
- Content: "",
+ Id: proposalId,
+ Request: &req,
+ Content: "",
ProposalStage: types.ProposalStage{
CancelFn: &cancel,
},
diff --git a/server/model/proposal/revise.go b/server/model/proposal/revise.go
deleted file mode 100644
index 5b0a1556..00000000
--- a/server/model/proposal/revise.go
+++ /dev/null
@@ -1 +0,0 @@
-package proposal
diff --git a/server/types/proposal.go b/server/types/proposal.go
index 1b7464a4..c9026660 100644
--- a/server/types/proposal.go
+++ b/server/types/proposal.go
@@ -5,9 +5,9 @@ import (
)
type Proposal struct {
- Id string
- ModelContext *shared.ModelContext
- Content string
+ Id string
+ Request *shared.PromptRequest
+ Content string
ProposalStage
PlanDescription *shared.PlanDescription
}
diff --git a/shared/reply.go b/shared/reply.go
index eadd644b..f6f28ecf 100644
--- a/shared/reply.go
+++ b/shared/reply.go
@@ -1,6 +1,8 @@
package shared
-import "strings"
+import (
+ "strings"
+)
type replyInfo struct {
lines []string
@@ -85,8 +87,10 @@ func (r *replyInfo) AddChunk(chunk string) {
}
if r.currentFilePath == "" {
+ // fmt.Println("Current file path is empty--checking for possible file path...")
+
var gotPath string
- if (strings.HasPrefix(prevFullLine, "-") && strings.HasSuffix(prevFullLine, ":")) || strings.HasPrefix(prevFullLine, "-file:") || strings.HasPrefix(prevFullLine, "- file:") || (strings.HasPrefix(prevFullLine, "**") && strings.HasSuffix(prevFullLine, "**")) {
+ if (strings.HasPrefix(prevFullLine, "-")) || strings.HasPrefix(prevFullLine, "-file:") || strings.HasPrefix(prevFullLine, "- file:") || (strings.HasPrefix(prevFullLine, "**") && strings.HasSuffix(prevFullLine, "**")) {
p := strings.TrimPrefix(prevFullLine, "**")
p = strings.TrimPrefix(p, "-")
p = strings.TrimSpace(p)
@@ -95,6 +99,8 @@ func (r *replyInfo) AddChunk(chunk string) {
p = strings.TrimSuffix(p, ":")
p = strings.TrimSpace(p)
gotPath = p
+ } else {
+ // fmt.Println("No possible file path detected.", strconv.Quote(prevFullLine))
}
if gotPath != "" {
@@ -113,8 +119,9 @@ func (r *replyInfo) AddChunk(chunk string) {
} else {
r.files[r.currentFilePath] = true
+ var tokens int
if r.countTokens {
- tokens := int(GetNumTokens(prevFullLine))
+ tokens = int(GetNumTokens(prevFullLine))
r.numTokensByFile[r.currentFilePath] += tokens
}
// r.contentByFile[r.currentFilePath] += prevFullLine + "\n"
diff --git a/shared/reply_test.go b/shared/reply_test.go
index 26e962c1..38e5f4c1 100644
--- a/shared/reply_test.go
+++ b/shared/reply_test.go
@@ -20,10 +20,21 @@ var examples = []TestExample{
FilePath: "reply_test_examples/2.md",
NumPaths: 2,
},
+ {
+ FilePath: "reply_test_examples/3.md",
+ NumPaths: 2,
+ },
+ {
+ FilePath: "reply_test_examples/4.md",
+ NumPaths: 1,
+ },
}
func TestReplyTokenCounter(t *testing.T) {
+
for _, example := range examples {
+ fmt.Println(example.FilePath)
+
bytes, err := os.ReadFile(example.FilePath)
if err != nil {
t.Error(err)
diff --git a/shared/reply_test_examples/3.md b/shared/reply_test_examples/3.md
new file mode 100644
index 00000000..c2bf218d
--- /dev/null
+++ b/shared/reply_test_examples/3.md
@@ -0,0 +1,105 @@
+Sure, here's how you could structure your 'context rm' command and 'context update' command using placeholders for the 'lib' functions that will handle the actual removal and updating of contexts:
+
+**cmd/context_rm.go**
+
+```go
+/*
+Copyright © 2023 NAME HERE <EMAIL ADDRESS>
+*/
+package cmd
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/spf13/cobra"
+)
+
+// contextRmCmd represents the delete command
+var contextRmCmd = &cobra.Command{
+ Use: "rm [context_name]",
+ Aliases: []string{"delete"},
+ Short: "",
+ Long: ``,
+ Run: contextRm,
+}
+
+func contextRm(cmd *cobra.Command, args []string) {
+ all, err := cmd.Flags().GetBool("all")
+
+ if err != nil {
+ log.Fatal("Error parsing all flag: ", err)
+ }
+
+ if all {
+ // Placeholder for lib function
+ err = lib.RemoveAllContexts()
+ if err != nil {
+ log.Fatal("Error removing all contexts: ", err)
+ }
+ } else if len(args) > 0 {
+ for _, contextName := range args {
+ // Placeholder for lib function
+ err = lib.RemoveContext(contextName)
+ if err != nil {
+ fmt.Printf("Error removing context '%s': %v\n", contextName, err)
+ }
+ }
+ } else {
+ fmt.Println("Please provide a context name or use the --all flag to remove all contexts.")
+ }
+}
+
+func init() {
+ contextCmd.AddCommand(contextRmCmd)
+ contextRmCmd.Flags().BoolP("all", "a", false, "remove all contexts")
+}
+```
+
+**cmd/context_update.go**
+
+```go
+/*
+Copyright © 2023 NAME HERE <EMAIL ADDRESS>
+*/
+package cmd
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/spf13/cobra"
+)
+
+// contextUpdateCmd represents the context command
+var contextUpdateCmd = &cobra.Command{
+ Use: "update [file-or-urls...]",
+ Short: "A brief description of your command",
+ Long: `A longer description that spans multiple lines and likely contains examples
+and usage of using your command. For example:
+
+Cobra is a CLI library for Go that empowers applications.
+This application is a tool to generate the needed files
+to quickly create a Cobra application.`,
+ Run: func(cmd *cobra.Command, args []string) {
+ if len(args) == 0 {
+ fmt.Println("Please provide one or more files or URLs to update.")
+ return
+ }
+
+ for _, arg := range args {
+ // Placeholder for lib function
+ err := lib.UpdateContext(arg)
+ if err != nil {
+ fmt.Printf("Error updating context for '%s': %v\n", arg, err)
+ }
+ }
+ },
+}
+
+func init() {
+ contextCmd.AddCommand(contextUpdateCmd)
+}
+```
+
+In your next iteration, you could implement the functions in 'lib' package such as `RemoveAllContexts`, `RemoveContext`, and `UpdateContext`.
diff --git a/shared/reply_test_examples/4.md b/shared/reply_test_examples/4.md
new file mode 100644
index 00000000..041a5933
--- /dev/null
+++ b/shared/reply_test_examples/4.md
@@ -0,0 +1,26 @@
+Yes, it does. Let's start by defining the types for `Section` and `SectionizeResponse`. For the Section type, we would need `name`, `content`, and an optional `subSections` field (to store any potentially nested sections).
+
+Here is the structure we can follow:
+
+1. A `Section` struct which contains a `Name` for the section, `Content` of the section, and a slice of `Subsection` for possible subsections in that section.
+2. A `SectionizeResponse` struct which contains a slice of `Section`.
+
+In `server/types/` directory, create a new `section.go` file.
+
+- server/types/section.go
+
+```go
+package types
+
+type Section struct {
+ Name string
+ Content string
+ Subsection []Section
+}
+
+type SectionizeResponse struct {
+ Sections []Section
+}
+```
+
+Once you have checked and confirmed this task, I will proceed to the next task which is creating a sectionize function in the server model.
diff --git a/shared/tokens.go b/shared/tokens.go
index 56aed94c..ce97f380 100644
--- a/shared/tokens.go
+++ b/shared/tokens.go
@@ -7,9 +7,9 @@ import (
"github.com/pkoukk/tiktoken-go"
)
-const MaxTokens uint32 = 8000
+const MaxTokens int = 8000
-func GetNumTokens(text string) (numTokens uint32) {
+func GetNumTokens(text string) (numTokens int) {
tkm, err := tiktoken.EncodingForModel("gpt-4")
if err != nil {
err = fmt.Errorf("encoding for model: %v", err)
@@ -17,5 +17,5 @@ func GetNumTokens(text string) (numTokens uint32) {
return
}
- return uint32(len(tkm.Encode(text, nil, nil)))
+ return len(tkm.Encode(text, nil, nil))
}
diff --git a/shared/types.go b/shared/types.go
index a23faaa2..973878c6 100644
--- a/shared/types.go
+++ b/shared/types.go
@@ -6,7 +6,6 @@ import (
type CurrentPlanFiles struct {
Files map[string]string `json:"files"`
- // Exec string `json:"exec"`
}
type PromptRequest struct {
@@ -33,17 +32,17 @@ type ModelContextPart struct {
Url string `json:"url"`
FilePath string `json:"filePath"`
Sha string `json:"sha"`
- NumTokens uint32 `json:"numTokens"`
+ NumTokens int `json:"numTokens"`
UpdatedAt string `json:"updatedAt"`
}
type ModelContext []ModelContextPart
type ModelContextState struct {
- NumTokens uint32 `json:"numTokens"`
+ NumTokens int `json:"numTokens"`
Counter uint32 `json:"counter"`
- ActiveTokens uint32 `json:"activeTokens"`
- ChatFlexPct uint8 `json:"chatFlexPct"`
- PlanFlexPct uint8 `json:"planFlexPct"`
+ ActiveTokens int `json:"activeTokens"`
+ ChatFlexPct int `json:"chatFlexPct"`
+ PlanFlexPct int `json:"planFlexPct"`
}
type PlanSettings struct {
@@ -54,12 +53,10 @@ type PlanChunk struct {
Type string `json:"type"`
FilePath string `json:"filePath"`
Content string `json:"content"`
- // IsExec bool `json:"isExec"`
}
type PlanDescription struct {
MadePlan bool `json:"madePlan"`
CommitMsg string `json:"commitMsg"`
Files []string `json:"files"`
- // HasExec bool `json:"hasExec"`
}