Skip to content

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

server-side first stab at prompt for missing file; add dev mode to cli fs paths to allow for switching between dev and cloud servers

Dane Schneider849c061fbb00
diff --git a/app/cli/fs/fs.go b/app/cli/fs/fs.go
index 4b7da769..b2788cb3 100644
--- a/app/cli/fs/fs.go
+++ b/app/cli/fs/fs.go
@@ -30,7 +30,19 @@ func init() {
if err != nil {
panic("Couldn't find home dir:" + err.Error())
}
- HomePlandexDir = filepath.Join(home, ".plandex-home")
+
+ if os.Getenv("PLANDEX_ENV") == "development" {
+ HomePlandexDir = filepath.Join(home, ".plandex-home-dev")
+ } else {
+ HomePlandexDir = filepath.Join(home, ".plandex-home")
+ }
+
+ // Create the home plandex directory if it doesn't exist
+ err = os.MkdirAll(HomePlandexDir, os.ModePerm)
+ if err != nil {
+ panic(err)
+ }
+
CacheDir = filepath.Join(HomePlandexDir, "cache")
HomeAuthPath = filepath.Join(HomePlandexDir, "auth.json")
HomeAccountsPath = filepath.Join(HomePlandexDir, "accounts.json")
@@ -55,7 +67,12 @@ func FindOrCreatePlandex() (string, bool, error) {
}
// Determine the directory path
- dir := filepath.Join(Cwd, ".plandex")
+ var dir string
+ if os.Getenv("PLANDEX_ENV") == "development" {
+ dir = filepath.Join(Cwd, ".plandex-dev")
+ } else {
+ dir = filepath.Join(Cwd, ".plandex")
+ }
err := os.Mkdir(dir, os.ModePerm)
if err != nil {
@@ -199,7 +216,12 @@ func GetPlandexIgnore() (*ignore.GitIgnore, error) {
func findPlandex() (string, string) {
searchPath := Cwd
for searchPath != "/" {
- dir := filepath.Join(searchPath, ".plandex")
+ var dir string
+ if os.Getenv("PLANDEX_ENV") == "development" {
+ dir = filepath.Join(searchPath, ".plandex-dev")
+ } else {
+ dir = filepath.Join(searchPath, ".plandex")
+ }
if _, err := os.Stat(dir); !os.IsNotExist(err) {
return dir, searchPath
}
diff --git a/app/cli/go.mod b/app/cli/go.mod
index f65388e3..0c7cdd13 100644
--- a/app/cli/go.mod
+++ b/app/cli/go.mod
@@ -18,6 +18,7 @@ require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
+ github.com/catppuccin/go v0.2.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cqroot/multichoose v0.1.1 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
@@ -45,10 +46,11 @@ require (
require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/briandowns/spinner v1.23.0
- github.com/charmbracelet/bubbles v0.16.1
- github.com/charmbracelet/bubbletea v0.24.2
+ github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6
+ github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/glow v1.5.1
+ github.com/charmbracelet/huh v0.3.0
github.com/cqroot/prompt v0.9.3
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/inconshreveable/mousetrap v1.1.0 // indirect
diff --git a/app/cli/go.sum b/app/cli/go.sum
index 710ca655..5f9b9e70 100644
--- a/app/cli/go.sum
+++ b/app/cli/go.sum
@@ -224,6 +224,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9MSK/jFM=
+github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
+github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -231,17 +233,23 @@ github.com/charmbracelet/bubbles v0.7.5/go.mod h1:IRTORFvhEI6OUH7WhN2Ks8Z8miNGim
github.com/charmbracelet/bubbles v0.15.0/go.mod h1:Y7gSFbBzlMpUDR/XM9MhZI374Q+1p1kluf1uLl8iK74=
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
+github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6 h1:6nVCV8pqGaeyxetur3gpX3AAaiyKgzjIoCPV3NXKZBE=
+github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o=
github.com/charmbracelet/bubbletea v0.12.2/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
github.com/charmbracelet/bubbletea v0.23.1/go.mod h1:JAfGK/3/pPKHTnAS8JIE2u9f61BjWTQY57RbT25aMXU=
github.com/charmbracelet/bubbletea v0.23.2/go.mod h1:FaP3WUivcTM0xOKNmhciz60M6I+weYLF76mr1JyI7sM=
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=
github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg=
+github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
+github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/charm v0.8.7/go.mod h1:ApJYwJljEjODkOYJgFDzbUqztLrCWQct9zyPD+xcVr4=
github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc=
github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc=
github.com/charmbracelet/glow v1.5.1 h1:o1mwT4xXXpkfUhJG6euQayNxLZf9yKctOCNHLztrwdE=
github.com/charmbracelet/glow v1.5.1/go.mod h1:rGgop0a2/4gXWiAxUW1iEQseoE+9Ctpb7M4sM9cY9CU=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
+github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
+github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
diff --git a/app/cli/lib/context_paths.go b/app/cli/lib/context_paths.go
index c8f4f81c..b060ef99 100644
--- a/app/cli/lib/context_paths.go
+++ b/app/cli/lib/context_paths.go
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"plandex/types"
+ "strings"
"sync"
)
@@ -31,7 +32,7 @@ func ParseInputPaths(fileOrDirPaths []string, params *types.LoadContextParams) (
}
if info.IsDir() {
- if info.Name() == ".git" || info.Name() == ".plandex" {
+ if info.Name() == ".git" || strings.Index(info.Name(), ".plandex") == 0 {
return filepath.SkipDir
}
diff --git a/app/cli/main.go b/app/cli/main.go
index 4bfe9390..9ef80e47 100644
--- a/app/cli/main.go
+++ b/app/cli/main.go
@@ -8,6 +8,7 @@ import (
"plandex/api"
"plandex/auth"
"plandex/cmd"
+ "plandex/fs"
)
func init() {
@@ -15,18 +16,7 @@ func init() {
// set up a file logger
// TODO: log rotation
- home, err := os.UserHomeDir()
- if err != nil {
- panic(err)
- }
-
- dir := filepath.Join(home, ".plandex-home")
- err = os.MkdirAll(dir, os.ModePerm)
- if err != nil {
- panic(err)
- }
-
- file, err := os.OpenFile(filepath.Join(dir, "plandex.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
+ file, err := os.OpenFile(filepath.Join(fs.HomePlandexDir, "plandex.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
fmt.Fprintf(os.Stderr, "Error opening log file: %v\n", err)
os.Exit(1)
diff --git a/app/cli/stream_tui/model.go b/app/cli/stream_tui/model.go
index 82302c6a..7f10059a 100644
--- a/app/cli/stream_tui/model.go
+++ b/app/cli/stream_tui/model.go
@@ -5,6 +5,7 @@ import (
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)
@@ -29,6 +30,8 @@ type streamUIModel struct {
height int
atScrollBottom bool
+
+ missingFilePrompt *huh.Select[string]
}
type keymap = struct {
@@ -83,11 +86,12 @@ func initialModel() *streamUIModel {
),
},
- tokensByPath: make(map[string]int),
- finishedByPath: make(map[string]bool),
- spinner: s,
- atScrollBottom: true,
- starting: true,
+ tokensByPath: make(map[string]int),
+ finishedByPath: make(map[string]bool),
+ spinner: s,
+ atScrollBottom: true,
+ starting: true,
+ missingFilePrompt: nil,
}
return &initialState
diff --git a/app/server/handlers/context_helper.go b/app/server/handlers/context_helper.go
new file mode 100644
index 00000000..2c64b571
--- /dev/null
+++ b/app/server/handlers/context_helper.go
@@ -0,0 +1,147 @@
+package handlers
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "log"
+ "net/http"
+ "plandex-server/db"
+ "plandex-server/types"
+
+ "github.com/google/uuid"
+ "github.com/plandex/plandex/shared"
+)
+
+func loadContexts(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth, loadReq *shared.LoadContextRequest, planId, branchName string) (*shared.LoadContextResponse, []*db.Context) {
+ branch, err := db.GetDbBranch(planId, branchName)
+ if err != nil {
+ log.Printf("Error getting branch: %v\n", err)
+ http.Error(w, "Error getting branch: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ }
+
+ maxTokens := shared.MaxContextTokens
+ tokensAdded := 0
+ totalTokens := branch.ContextTokens
+
+ paramsByTempId := make(map[string]*shared.LoadContextParams)
+ numTokensByTempId := make(map[string]int)
+
+ for _, context := range *loadReq {
+ tempId := uuid.New().String()
+ numTokens, err := shared.GetNumTokens(context.Body)
+
+ if err != nil {
+ log.Printf("Error getting num tokens: %v\n", err)
+ http.Error(w, "Error getting num tokens: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ }
+
+ paramsByTempId[tempId] = context
+ numTokensByTempId[tempId] = numTokens
+
+ tokensAdded += numTokens
+ totalTokens += numTokens
+ }
+
+ if totalTokens > maxTokens {
+ log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d)", totalTokens, maxTokens)
+ res := shared.LoadContextResponse{
+ TokensAdded: tokensAdded,
+ TotalTokens: totalTokens,
+ MaxTokensExceeded: true,
+ }
+
+ bytes, err := json.Marshal(res)
+
+ if err != nil {
+ log.Printf("Error marshalling response: %v\n", err)
+ http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ }
+
+ w.Write(bytes)
+ return nil, nil
+ }
+
+ unlockFn := lockRepo(w, r, auth, db.LockScopeWrite)
+ if unlockFn == nil {
+ return nil, nil
+ } else {
+ defer (*unlockFn)()
+ }
+
+ dbContextsCh := make(chan *db.Context)
+ errCh := make(chan error)
+ for tempId, params := range paramsByTempId {
+
+ go func(tempId string, params *shared.LoadContextParams) {
+ hash := sha256.Sum256([]byte(params.Body))
+ sha := hex.EncodeToString(hash[:])
+
+ context := db.Context{
+ // Id generated by db layer
+ OrgId: auth.OrgId,
+ OwnerId: auth.User.Id,
+ PlanId: planId,
+ ContextType: params.ContextType,
+ Name: params.Name,
+ Url: params.Url,
+ FilePath: params.FilePath,
+ NumTokens: numTokensByTempId[tempId],
+ Sha: sha,
+ Body: params.Body,
+ }
+
+ err := db.StoreContext(&context)
+
+ if err != nil {
+ errCh <- err
+ return
+ }
+
+ dbContextsCh <- &context
+
+ }(tempId, params)
+ }
+
+ var dbContexts []*db.Context
+ var apiContexts []*shared.Context
+
+ for i := 0; i < len(*loadReq); i++ {
+ select {
+ case err := <-errCh:
+ log.Printf("Error creating context: %v\n", err)
+ http.Error(w, "Error creating context: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ case dbContext := <-dbContextsCh:
+ dbContexts = append(dbContexts, dbContext)
+ apiContext := dbContext.ToApi()
+ apiContext.Body = ""
+ apiContexts = append(apiContexts, apiContext)
+ }
+ }
+
+ commitMsg := shared.SummaryForLoadContext(apiContexts, tokensAdded, totalTokens) + "\n\n" + shared.TableForLoadContext(apiContexts)
+ err = db.GitAddAndCommit(auth.OrgId, planId, branchName, commitMsg)
+
+ if err != nil {
+ log.Printf("Error committing changes: %v\n", err)
+ http.Error(w, "Error committing changes: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ }
+
+ err = db.AddPlanContextTokens(planId, branchName, tokensAdded)
+ if err != nil {
+ log.Printf("Error updating plan tokens: %v\n", err)
+ http.Error(w, "Error updating plan tokens: "+err.Error(), http.StatusInternalServerError)
+ return nil, nil
+ }
+
+ return &shared.LoadContextResponse{
+ TokensAdded: tokensAdded,
+ TotalTokens: totalTokens,
+ Msg: commitMsg,
+ }, dbContexts
+}
diff --git a/app/server/handlers/plans_context.go b/app/server/handlers/plans_context.go
index 660609ad..ffb7be5e 100644
--- a/app/server/handlers/plans_context.go
+++ b/app/server/handlers/plans_context.go
@@ -11,7 +11,6 @@ import (
"plandex-server/db"
"sync"
- "github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/plandex/plandex/shared"
)
@@ -71,7 +70,6 @@ func LoadContextHandler(w http.ResponseWriter, r *http.Request) {
if auth == nil {
return
}
- currentUserId := auth.User.Id
vars := mux.Vars(r)
planId := vars["planId"]
@@ -83,13 +81,6 @@ func LoadContextHandler(w http.ResponseWriter, r *http.Request) {
return
}
- branch, err := db.GetDbBranch(planId, branchName)
- if err != nil {
- log.Printf("Error getting branch: %v\n", err)
- http.Error(w, "Error getting branch: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
// read the request body
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -106,128 +97,11 @@ func LoadContextHandler(w http.ResponseWriter, r *http.Request) {
return
}
- maxTokens := shared.MaxContextTokens
- tokensAdded := 0
- totalTokens := branch.ContextTokens
-
- paramsByTempId := make(map[string]*shared.LoadContextParams)
- numTokensByTempId := make(map[string]int)
-
- for _, context := range requestBody {
- tempId := uuid.New().String()
- numTokens, err := shared.GetNumTokens(context.Body)
-
- if err != nil {
- log.Printf("Error getting num tokens: %v\n", err)
- http.Error(w, "Error getting num tokens: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- paramsByTempId[tempId] = context
- numTokensByTempId[tempId] = numTokens
-
- tokensAdded += numTokens
- totalTokens += numTokens
- }
-
- if totalTokens > maxTokens {
- log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d)", totalTokens, maxTokens)
- res := shared.LoadContextResponse{
- TokensAdded: tokensAdded,
- TotalTokens: totalTokens,
- MaxTokensExceeded: true,
- }
-
- bytes, err := json.Marshal(res)
-
- if err != nil {
- log.Printf("Error marshalling response: %v\n", err)
- http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- w.Write(bytes)
- return
- }
-
- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite)
- if unlockFn == nil {
- return
- } else {
- defer (*unlockFn)()
- }
-
- dbContextsCh := make(chan *db.Context)
- errCh := make(chan error)
- for tempId, params := range paramsByTempId {
-
- go func(tempId string, params *shared.LoadContextParams) {
- hash := sha256.Sum256([]byte(params.Body))
- sha := hex.EncodeToString(hash[:])
-
- context := db.Context{
- // Id generated by db layer
- OrgId: auth.OrgId,
- OwnerId: currentUserId,
- PlanId: planId,
- ContextType: params.ContextType,
- Name: params.Name,
- Url: params.Url,
- FilePath: params.FilePath,
- NumTokens: numTokensByTempId[tempId],
- Sha: sha,
- Body: params.Body,
- }
-
- err := db.StoreContext(&context)
-
- if err != nil {
- errCh <- err
- return
- }
-
- dbContextsCh <- &context
-
- }(tempId, params)
- }
-
- var apiContexts []*shared.Context
-
- for i := 0; i < len(requestBody); i++ {
- select {
- case err := <-errCh:
- log.Printf("Error creating context: %v\n", err)
- http.Error(w, "Error creating context: "+err.Error(), http.StatusInternalServerError)
- return
- case dbContext := <-dbContextsCh:
- apiContext := dbContext.ToApi()
- apiContext.Body = ""
- apiContexts = append(apiContexts, apiContext)
- }
- }
-
- commitMsg := shared.SummaryForLoadContext(apiContexts, tokensAdded, totalTokens) + "\n\n" + shared.TableForLoadContext(apiContexts)
- err = db.GitAddAndCommit(auth.OrgId, planId, branchName, commitMsg)
-
- if err != nil {
- log.Printf("Error committing changes: %v\n", err)
- http.Error(w, "Error committing changes: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- err = db.AddPlanContextTokens(planId, branchName, tokensAdded)
- if err != nil {
- log.Printf("Error updating plan tokens: %v\n", err)
- http.Error(w, "Error updating plan tokens: "+err.Error(), http.StatusInternalServerError)
+ res, _ := loadContexts(w, r, auth, &requestBody, planId, branchName)
+ if res == nil {
return
}
- res := shared.LoadContextResponse{
- TokensAdded: tokensAdded,
- TotalTokens: totalTokens,
- Msg: commitMsg,
- }
-
bytes, err := json.Marshal(res)
if err != nil {
diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.go
index e20df21a..ff9c7ff5 100644
--- a/app/server/handlers/plans_exec.go
+++ b/app/server/handlers/plans_exec.go
@@ -2,13 +2,11 @@ package handlers
import (
"encoding/json"
- "fmt"
"io"
"log"
"net/http"
"os"
"plandex-server/db"
- "plandex-server/host"
"plandex-server/model"
modelPlan "plandex-server/model/plan"
"plandex-server/types"
@@ -149,49 +147,26 @@ func ConnectPlanHandler(w http.ResponseWriter, r *http.Request) {
func StopPlanHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for StopPlanHandler")
- auth := authenticate(w, r, true)
- if auth == nil {
- return
- }
vars := mux.Vars(r)
planId := vars["planId"]
branch := vars["branch"]
-
log.Println("planId: ", planId)
-
- if authorizePlan(w, planId, auth) == nil {
- return
- }
-
+ log.Println("branch: ", branch)
active := modelPlan.GetActivePlan(planId, branch)
if active == nil {
- modelStream, err := db.GetActiveModelStream(planId, branch)
-
- if err != nil {
- log.Printf("Error getting active model stream: %v\n", err)
- http.Error(w, "Error getting active model stream", http.StatusInternalServerError)
- return
- }
+ proxyActivePlanMethod(w, r, planId, branch, "stop")
+ return
+ }
- if modelStream == nil {
- log.Printf("No active model stream for plan %s\n", planId)
- http.Error(w, "No active model stream for plan", http.StatusNotFound)
- return
- }
+ auth := authenticate(w, r, true)
+ if auth == nil {
+ return
+ }
- if modelStream.InternalIp == host.Ip {
- db.SetModelStreamFinished(modelStream.Id)
- log.Printf("No active plan for plan %s\n", planId)
- http.Error(w, "No active plan for plan", http.StatusNotFound)
- return
- } else {
- log.Printf("Forwarding request to %s\n", modelStream.InternalIp)
- proxyUrl := fmt.Sprintf("http://%s:%s/plans/%s/%s/stop", modelStream.InternalIp, os.Getenv("EXTERNAL_PORT"), planId, branch)
- proxyRequest(w, r, proxyUrl)
- return
- }
+ if authorizePlan(w, planId, auth) == nil {
+ return
}
unlockFn := lockRepo(w, r, auth, db.LockScopeWrite)
@@ -211,3 +186,69 @@ func StopPlanHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Successfully processed request for StopPlanHandler")
}
+
+func RespondMissingFileHandler(w http.ResponseWriter, r *http.Request) {
+ log.Println("Received request for RespondMissingFileHandler")
+
+ vars := mux.Vars(r)
+ planId := vars["planId"]
+ branch := vars["branch"]
+ log.Println("planId: ", planId)
+ log.Println("branch: ", branch)
+
+ active := modelPlan.GetActivePlan(planId, branch)
+ if active == nil {
+ proxyActivePlanMethod(w, r, planId, branch, "respond_missing_file")
+ return
+ }
+
+ auth := authenticate(w, r, true)
+ if auth == nil {
+ return
+ }
+
+ if authorizePlan(w, planId, auth) == nil {
+ return
+ }
+
+ // read the request body
+ body, err := io.ReadAll(r.Body)
+ if err != nil {
+ log.Printf("Error reading request body: %v\n", err)
+ http.Error(w, "Error reading request body", http.StatusInternalServerError)
+ return
+ }
+ defer r.Body.Close()
+
+ var requestBody shared.RespondMissingFileRequest
+ if err := json.Unmarshal(body, &requestBody); err != nil {
+ log.Printf("Error parsing request body: %v\n", err)
+ http.Error(w, "Error parsing request body", http.StatusBadRequest)
+ return
+ }
+
+ if requestBody.Choice == shared.RespondMissingFileChoiceLoad {
+ res, dbContexts := loadContexts(w, r, auth, &shared.LoadContextRequest{
+ &shared.LoadContextParams{
+ ContextType: shared.ContextFileType,
+ Name: requestBody.FilePath,
+ FilePath: requestBody.FilePath,
+ Body: requestBody.Body,
+ },
+ }, planId, branch)
+ if res == nil {
+ return
+ }
+
+ dbContext := dbContexts[0]
+ modelPlan.UpdateActivePlan(planId, branch, func(activePlan *types.ActivePlan) {
+ activePlan.Contexts = append(activePlan.Contexts, dbContext)
+ activePlan.ContextsByPath[dbContext.FilePath] = dbContext
+ })
+ }
+
+ // This will resume model stream
+ active.MissingFileResponseCh <- requestBody.Choice
+
+ log.Println("Successfully processed request for RespondMissingFileHandler")
+}
diff --git a/app/server/handlers/proxy_helper.go b/app/server/handlers/proxy_helper.go
index c6a619cd..a867efa2 100644
--- a/app/server/handlers/proxy_helper.go
+++ b/app/server/handlers/proxy_helper.go
@@ -1,11 +1,43 @@
package handlers
import (
+ "fmt"
"io"
"log"
"net/http"
+ "os"
+ "plandex-server/db"
+ "plandex-server/host"
)
+func proxyActivePlanMethod(w http.ResponseWriter, r *http.Request, planId, branch, method string) {
+ modelStream, err := db.GetActiveModelStream(planId, branch)
+
+ if err != nil {
+ log.Printf("Error getting active model stream: %v\n", err)
+ http.Error(w, "Error getting active model stream", http.StatusInternalServerError)
+ return
+ }
+
+ if modelStream == nil {
+ log.Printf("No active model stream for plan %s\n", planId)
+ http.Error(w, "No active model stream for plan", http.StatusNotFound)
+ return
+ }
+
+ if modelStream.InternalIp == host.Ip {
+ db.SetModelStreamFinished(modelStream.Id)
+ log.Printf("No active plan for plan %s\n", planId)
+ http.Error(w, "No active plan for plan", http.StatusNotFound)
+ return
+ } else {
+ log.Printf("Forwarding request to %s\n", modelStream.InternalIp)
+ proxyUrl := fmt.Sprintf("http://%s:%s/plans/%s/%s/%s", modelStream.InternalIp, os.Getenv("EXTERNAL_PORT"), planId, branch, method)
+ proxyRequest(w, r, proxyUrl)
+ return
+ }
+}
+
func proxyRequest(w http.ResponseWriter, originalRequest *http.Request, url string) {
client := &http.Client{}
@@ -24,6 +56,11 @@ func proxyRequest(w http.ResponseWriter, originalRequest *http.Request, url stri
}
}
+ // Copy the body from the original request to the new request if it's a POST or PUT
+ if originalRequest.Method == http.MethodPost || originalRequest.Method == http.MethodPut {
+ req.Body = originalRequest.Body
+ }
+
// Make the request
resp, err := client.Do(req)
if err != nil {
diff --git a/app/server/host/ip.go b/app/server/host/ip.go
index 19d4c657..0b77dcdf 100644
--- a/app/server/host/ip.go
+++ b/app/server/host/ip.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
+ "log"
"net/http"
"os"
)
@@ -24,6 +25,9 @@ func LoadIp() error {
if err != nil {
return fmt.Errorf("error getting AWS ECS IP: %v", err)
}
+
+ log.Println("Got AWS ECS IP: ", Ip)
+
} else if os.Getenv("IP") != "" {
Ip = os.Getenv("IP")
return nil
diff --git a/app/server/model/plan/build.go b/app/server/model/plan/build.go
index 3f10df05..c57925d1 100644
--- a/app/server/model/plan/build.go
+++ b/app/server/model/plan/build.go
@@ -99,15 +99,6 @@ func execPlanBuild(client *openai.Client, currentOrgId, currentUserId, branch st
errCh <- nil
}()
- go func() {
- err := db.SetPlanStatus(planId, branch, shared.PlanStatusBuilding, "")
- if err != nil {
- errCh <- fmt.Errorf("error setting plan status to building: %v", err)
- return
- }
- errCh <- nil
- }()
-
go func() {
res, err := db.GetCurrentPlanState(db.CurrentPlanStateParams{
OrgId: currentOrgId,
@@ -121,7 +112,7 @@ func execPlanBuild(client *openai.Client, currentOrgId, currentUserId, branch st
errCh <- nil
}()
- for i := 0; i < 3; i++ {
+ for i := 0; i < 2; i++ {
err := <-errCh
if err != nil {
log.Printf("Error building plan %s: %v\n", planId, err)
diff --git a/app/server/model/plan/tell.go b/app/server/model/plan/tell.go
index 408668f5..30f41000 100644
--- a/app/server/model/plan/tell.go
+++ b/app/server/model/plan/tell.go
@@ -65,16 +65,17 @@ func Tell(client *openai.Client, plan *db.Plan, branch string, auth *types.Serve
log.Println("Model stream id:", modelStream.Id)
- go execTellPlan(client, plan, branch, auth, req, active, 0)
+ go execTellPlan(client, plan, branch, auth, req, active, 0, "")
return nil
}
-func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *types.ServerAuth, req *shared.TellPlanRequest, active *types.ActivePlan, iteration int) {
+func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *types.ServerAuth, req *shared.TellPlanRequest, active *types.ActivePlan, iteration int, missingFileResponse shared.RespondMissingFileChoice) {
currentUserId := auth.User.Id
currentOrgId := auth.OrgId
- if os.Getenv("IS_CLOUD") != "" {
+ if os.Getenv("IS_CLOUD") != "" &&
+ missingFileResponse == "" {
if auth.User.IsTrial {
if plan.TotalReplies >= types.TrialMaxReplies {
active.StreamDoneCh <- &shared.ApiError{
@@ -104,7 +105,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
}
lockScope := db.LockScopeWrite
- if iteration > 0 {
+ if iteration > 0 || missingFileResponse != "" {
lockScope = db.LockScopeRead
}
repoLockId, err := db.LockRepo(auth.OrgId, auth.User.Id, planId, branch, lockScope)
@@ -156,13 +157,17 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
}()
go func() {
- res, err := db.GetPlanContexts(currentOrgId, planId, true)
- if err != nil {
- log.Printf("Error getting plan modelContext: %v\n", err)
- errCh <- fmt.Errorf("error getting plan modelContext: %v", err)
- return
+ if iteration > 0 || missingFileResponse != "" {
+ modelContext = active.Contexts
+ } else {
+ res, err := db.GetPlanContexts(currentOrgId, planId, true)
+ if err != nil {
+ log.Printf("Error getting plan modelContext: %v\n", err)
+ errCh <- fmt.Errorf("error getting plan modelContext: %v", err)
+ return
+ }
+ modelContext = res
}
- modelContext = res
errCh <- nil
}()
@@ -185,7 +190,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
innerErrCh := make(chan error)
go func() {
- if iteration == 0 {
+ if iteration == 0 && missingFileResponse == "" {
userMsg := db.ConvoMessage{
OrgId: currentOrgId,
PlanId: planId,
@@ -270,7 +275,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
return
}
- if iteration == 0 {
+ if iteration == 0 && missingFileResponse == "" {
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
ap.Contexts = modelContext
ap.PromptMessageNum = len(convo) + 1
@@ -281,7 +286,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
}
}
})
- } else {
+ } else if missingFileResponse == "" {
// reset current reply content and num tokens
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
ap.CurrentReplyContent = ""
@@ -316,7 +321,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
numPromptTokens int
promptTokens int
)
- if iteration == 0 {
+ if iteration == 0 && missingFileResponse == "" {
numPromptTokens, err = shared.GetNumTokens(req.Prompt)
if err != nil {
err = fmt.Errorf("error getting number of tokens in prompt: %v", err)
@@ -468,6 +473,12 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
}
}
+ replyId := uuid.New().String()
+ replyParser := types.NewReplyParser()
+ replyFiles := []string{}
+ replyNumTokens := 0
+
+ var promptMessage *openai.ChatCompletionMessage
var prompt string
if iteration == 0 {
prompt = req.Prompt
@@ -475,22 +486,69 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
prompt = "Continue the plan."
}
- promptMessage := &openai.ChatCompletionMessage{
+ promptMessage = &openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleUser,
Content: fmt.Sprintf(prompts.PromptWrapperFormatStr, prompt),
}
- messages = append(messages, *promptMessage)
+
+ if missingFileResponse == "" {
+ messages = append(messages, *promptMessage)
+ } else {
+ replyParser.AddChunk(active.CurrentReplyContent, true)
+ res := replyParser.Read()
+ currentFile := res.CurrentFilePath
+
+ replyContent := active.CurrentReplyContent
+ numTokens := active.NumTokens
+
+ if missingFileResponse == shared.RespondMissingFileChoiceSkip {
+ replyBeforeCurrentFile := replyParser.GetReplyBeforeCurrentPath()
+ numTokens, err = shared.GetNumTokens(replyBeforeCurrentFile)
+ if err != nil {
+ log.Printf("Error getting num tokens for reply before current file: %v\n", err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error getting num tokens for reply before current file",
+ }
+ return
+ }
+
+ replyContent = replyBeforeCurrentFile
+ replyParser = types.NewReplyParser()
+ replyParser.AddChunk(replyContent, true)
+
+ userAction := fmt.Sprintf("\n\n**User action.** You chose not to update the file `%s`, so I'll skip this update.\n\n", currentFile)
+
+ replyParser.AddChunk(userAction, false)
+ replyContent += userAction
+
+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
+ ap.CurrentReplyContent = replyContent
+ ap.NumTokens = numTokens
+ })
+
+ } else if missingFileResponse == shared.RespondMissingFileChoiceOverwrite {
+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
+ ap.AllowOverwritePaths[currentFile] = true
+ })
+ }
+
+ }
+
+ messages = append(messages, openai.ChatCompletionMessage{
+ Role: openai.ChatMessageRoleAssistant,
+ Content: active.CurrentReplyContent,
+ })
+
+ replyNumTokens = active.NumTokens
+ replyFiles = active.Files
// log.Println("\n\nMessages:")
// for _, message := range messages {
// log.Printf("%s: %s\n", message.Role, message.Content)
// }
- replyId := uuid.New().String()
- replyParser := types.NewReplyParser()
- replyFiles := []string{}
- replyNumTokens := 0
-
modelReq := openai.ChatCompletionRequest{
Model: model.PlannerModel,
Messages: messages,
@@ -499,7 +557,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
TopP: 0.7,
}
- stream, err := client.CreateChatCompletionStream(active.Ctx, modelReq)
+ stream, err := client.CreateChatCompletionStream(active.ModelStreamCtx, modelReq)
if err != nil {
log.Printf("Error creating proposal GPT4 stream: %v\n", err)
log.Println(err)
@@ -520,7 +578,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
storeAssistantReply := func() (*db.ConvoMessage, []string, string, error) {
num := len(convo) + 1
- if iteration == 0 {
+ if iteration == 0 && missingFileResponse == "" {
num++
}
@@ -757,7 +815,7 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
if req.AutoContinue && shouldContinue {
// continue plan
- execTellPlan(client, plan, branch, auth, req, active, iteration+1)
+ execTellPlan(client, plan, branch, auth, req, active, iteration+1, "")
} else {
if GetActivePlan(planId, branch).BuildFinished() {
active.Stream(shared.StreamMessage{
@@ -787,10 +845,54 @@ func execTellPlan(client *openai.Client, plan *db.Plan, branch string, auth *typ
})
replyParser.AddChunk(content, true)
- files, fileContents, _, numTokens := replyParser.Read()
- replyNumTokens = numTokens
+ res := replyParser.Read()
+
+ files := res.Files
+ fileContents := res.FileContents
+ replyNumTokens = res.TotalTokens
+ currentFile := res.CurrentFilePath
- // log.Printf("Reply num tokens: %d\n", replyNumTokens)
+ if currentFile != "" &&
+ active.ContextsByPath[currentFile] == nil &&
+ req.ProjectPaths[currentFile] {
+ // attempting to overwrite a file that isn't in context
+ // we will stop the stream and ask the user what to do
+ err := db.SetPlanStatus(planId, branch, shared.PlanStatusPrompting, "")
+
+ if err != nil {
+ log.Printf("Error setting plan %s status to prompting: %v\n", planId, err)
+ active.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Error setting plan status to prompting",
+ }
+ return
+ }
+
+ active.Stream(shared.StreamMessage{
+ Type: shared.StreamMessagePromptMissingFile,
+ MissingFilePath: currentFile,
+ })
+
+ // stop stream for now
+ active.CancelModelStreamFn()
+
+ // wait for user response to come in
+ userChoice := <-active.MissingFileResponseCh
+
+ // continue plan
+ execTellPlan(
+ client,
+ plan,
+ branch,
+ auth,
+ req,
+ active,
+ iteration, // keep the same iteration
+ userChoice,
+ )
+ return
+ }
if len(files) > len(replyFiles) {
log.Printf("Files: %v\n", files)
diff --git a/app/server/routes.go b/app/server/routes.go
index e961d63d..8f7f1eb5 100644
--- a/app/server/routes.go
+++ b/app/server/routes.go
@@ -55,6 +55,9 @@ func routes() *mux.Router {
r.HandleFunc("/plans/{planId}", handlers.DeletePlanHandler).Methods("DELETE")
r.HandleFunc("/plans/{planId}/{branch}/tell", handlers.TellPlanHandler).Methods("POST")
+
+ r.HandleFunc("/plans/{planId}/{branch}/respond_missing_file", handlers.RespondMissingFileHandler).Methods("POST")
+
r.HandleFunc("/plans/{planId}/{branch}/build", handlers.BuildPlanHandler).Methods("PATCH")
r.HandleFunc("/plans/{planId}/{branch}/connect", handlers.ConnectPlanHandler).Methods("PATCH")
r.HandleFunc("/plans/{planId}/{branch}/stop", handlers.StopPlanHandler).Methods("DELETE")
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index 2e3d1ce3..f123a2f5 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -21,47 +21,56 @@ type ActiveBuild struct {
}
type ActivePlan struct {
- Id string
- Branch string
- Prompt string
- Ctx context.Context
- CancelFn context.CancelFunc
- Contexts []*db.Context
- ContextsByPath map[string]*db.Context
- Files []string
- BuiltFiles map[string]bool
- IsBuildingByPath map[string]bool
- CurrentReplyContent string
- NumTokens int
- PromptMessageNum int
- BuildQueuesByPath map[string][]*ActiveBuild
- RepliesFinished bool
- StreamDoneCh chan *shared.ApiError
-
- ModelStreamId string
- IsBackground bool
- streamCh chan string
- subscriptions map[string]chan string
+ Id string
+ Branch string
+ Prompt string
+ Ctx context.Context
+ CancelFn context.CancelFunc
+ ModelStreamCtx context.Context
+ CancelModelStreamFn context.CancelFunc
+ Contexts []*db.Context
+ ContextsByPath map[string]*db.Context
+ Files []string
+ BuiltFiles map[string]bool
+ IsBuildingByPath map[string]bool
+ CurrentReplyContent string
+ NumTokens int
+ PromptMessageNum int
+ BuildQueuesByPath map[string][]*ActiveBuild
+ RepliesFinished bool
+ StreamDoneCh chan *shared.ApiError
+ ModelStreamId string
+ IsBackground bool
+ MissingFileResponseCh chan shared.RespondMissingFileChoice
+ AllowOverwritePaths map[string]bool
+ streamCh chan string
+ subscriptions map[string]chan string
}
func NewActivePlan(planId, branch, prompt string) *ActivePlan {
ctx, cancel := context.WithCancel(context.Background())
+ // child context for model stream so we can cancel it separately if needed
+ modelStreamCtx, cancelModelStream := context.WithCancel(ctx)
active := ActivePlan{
- Id: planId,
- Branch: branch,
- Prompt: prompt,
- Ctx: ctx,
- CancelFn: cancel,
- BuildQueuesByPath: map[string][]*ActiveBuild{},
- Contexts: []*db.Context{},
- ContextsByPath: map[string]*db.Context{},
- Files: []string{},
- BuiltFiles: map[string]bool{},
- IsBuildingByPath: map[string]bool{},
- StreamDoneCh: make(chan *shared.ApiError),
- streamCh: make(chan string),
- subscriptions: map[string]chan string{},
+ Id: planId,
+ Branch: branch,
+ Prompt: prompt,
+ Ctx: ctx,
+ CancelFn: cancel,
+ ModelStreamCtx: modelStreamCtx,
+ CancelModelStreamFn: cancelModelStream,
+ BuildQueuesByPath: map[string][]*ActiveBuild{},
+ Contexts: []*db.Context{},
+ ContextsByPath: map[string]*db.Context{},
+ Files: []string{},
+ BuiltFiles: map[string]bool{},
+ IsBuildingByPath: map[string]bool{},
+ StreamDoneCh: make(chan *shared.ApiError),
+ MissingFileResponseCh: make(chan shared.RespondMissingFileChoice),
+ AllowOverwritePaths: map[string]bool{},
+ streamCh: make(chan string),
+ subscriptions: map[string]chan string{},
}
go func() {
@@ -97,6 +106,10 @@ func (ap *ActivePlan) Stream(msg shared.StreamMessage) {
}
}
+func (ap *ActivePlan) ResetModelCtx() {
+ ap.ModelStreamCtx, ap.CancelModelStreamFn = context.WithCancel(context.Background())
+}
+
func (ap *ActivePlan) BuildFinished() bool {
for path := range ap.BuildQueuesByPath {
if !ap.PathFinished(path) {
diff --git a/app/server/types/reply.go b/app/server/types/reply.go
index d8a7cddb..bbe99176 100644
--- a/app/server/types/reply.go
+++ b/app/server/types/reply.go
@@ -4,6 +4,14 @@ import (
"strings"
)
+type parserRes struct {
+ CurrentFilePath string
+ Files []string
+ FileContents []string
+ NumTokensByFile map[string]int
+ TotalTokens int
+}
+
type replyParser struct {
lines []string
currentFileLines []string
@@ -109,22 +117,14 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {
// log.Println("Current file path is empty--checking for possible file path...")
var gotPath string
- if (strings.HasPrefix(prevFullLineTrimmed, "-")) || strings.HasPrefix(prevFullLineTrimmed, "-file:") || strings.HasPrefix(prevFullLineTrimmed, "- file:") || (strings.HasPrefix(prevFullLineTrimmed, "**") && strings.HasSuffix(prevFullLineTrimmed, "**")) {
- p := strings.TrimPrefix(prevFullLineTrimmed, "**")
- p = strings.TrimPrefix(p, "-")
- p = strings.TrimSpace(p)
- p = strings.TrimSuffix(p, "**")
- p = strings.TrimPrefix(p, "file:")
- p = strings.TrimSuffix(p, ":")
- p = strings.TrimSpace(p)
- gotPath = p
+ if lineHasFilePath(prevFullLineTrimmed) {
+ gotPath = extractFilePath(prevFullLineTrimmed)
} else {
// log.Println("No possible file path detected.", strconv.Quote(prevFullLineTrimmed))
}
if gotPath != "" {
// log.Println("Detected possible file path:", gotPath) // Logging the possible file path
-
if r.maybeFilePath == "" {
r.maybeFilePath = gotPath
} else {
@@ -133,7 +133,6 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {
}
} else {
// log.Println("Current file path is not empty--adding to current file...")
-
if strings.HasPrefix(prevFullLineTrimmed, "```") {
// log.Println("Found closing ticks--adding file to files and resetting current file...")
r.files = append(r.files, r.currentFilePath)
@@ -148,11 +147,49 @@ func (r *replyParser) AddChunk(chunk string, addToTotal bool) {
}
}
-func (r *replyParser) Read() (files []string, fileContents []string, numTokensByFile map[string]int, totalTokens int) {
- return r.files, r.fileContents, r.numTokensByFile, r.numTokens
+func (r *replyParser) Read() parserRes {
+ return parserRes{
+ CurrentFilePath: r.currentFilePath,
+ Files: r.files,
+ FileContents: r.fileContents,
+ NumTokensByFile: r.numTokensByFile,
+ TotalTokens: r.numTokens,
+ }
}
-func (r *replyParser) FinishAndRead() (files []string, fileContents []string, numTokensByFile map[string]int, totalTokens int) {
+func (r *replyParser) FinishAndRead() parserRes {
r.AddChunk("\n", false)
return r.Read()
}
+
+func (r *replyParser) GetReplyBeforeCurrentPath() string {
+ if r.currentFilePath == "" {
+ return strings.Join(r.lines, "\n")
+ }
+
+ var idx int
+ for i := len(r.lines) - 1; i >= 0; i-- {
+ line := r.lines[i]
+ if lineHasFilePath(line) && r.currentFilePath == extractFilePath(line) {
+ idx = i
+ break
+ }
+ }
+
+ return strings.Join(r.lines[:idx], "\n")
+}
+
+func lineHasFilePath(line string) bool {
+ return (strings.HasPrefix(line, "-")) || strings.HasPrefix(line, "-file:") || strings.HasPrefix(line, "- file:") || (strings.HasPrefix(line, "**") && strings.HasSuffix(line, "**"))
+}
+
+func extractFilePath(line string) string {
+ p := strings.TrimPrefix(line, "**")
+ p = strings.TrimPrefix(p, "-")
+ p = strings.TrimSpace(p)
+ p = strings.TrimSuffix(p, "**")
+ p = strings.TrimPrefix(p, "file:")
+ p = strings.TrimSuffix(p, ":")
+ p = strings.TrimSpace(p)
+ return p
+}
diff --git a/app/server/types/reply_test.go b/app/server/types/reply_test.go
index 518ba7cf..b6c7899c 100644
--- a/app/server/types/reply_test.go
+++ b/app/server/types/reply_test.go
@@ -85,7 +85,12 @@ func TestReplyTokenCounter(t *testing.T) {
i = end
}
- files, fileContents, tokensByFilePath, totalCounted := counter.FinishAndRead()
+ res := counter.FinishAndRead()
+
+ totalCounted := res.TotalTokens
+ files := res.Files
+ fileContents := res.FileContents
+ tokensByFilePath := res.NumTokensByFile
fmt.Printf("Total tokens counted: %d\n", totalCounted)
fmt.Printf("%d files: %v\n", len(files), files)
diff --git a/app/shared/models.go b/app/shared/models.go
index 67cffd61..4906d1c8 100644
--- a/app/shared/models.go
+++ b/app/shared/models.go
@@ -41,7 +41,7 @@ const (
PlanStatusDraft PlanStatus = "draft"
PlanStatusReplying PlanStatus = "replying"
PlanStatusDescribing PlanStatus = "describing"
- PlanStatusBuilding PlanStatus = "building"
+ PlanStatusPrompting PlanStatus = "prompting"
PlanStatusFinished PlanStatus = "finished"
PlanStatusStopped PlanStatus = "stopped"
PlanStatusError PlanStatus = "error"
diff --git a/app/shared/req_res.go b/app/shared/req_res.go
index 97e4e127..efc09485 100644
--- a/app/shared/req_res.go
+++ b/app/shared/req_res.go
@@ -97,6 +97,21 @@ type TellPlanRequest struct {
ProjectPaths map[string]bool `json:"projectPaths"`
}
+type RespondMissingFileChoice string
+
+const (
+ RespondMissingFileChoiceLoad RespondMissingFileChoice = "load"
+ RespondMissingFileChoiceSkip RespondMissingFileChoice = "skip"
+ RespondMissingFileChoiceOverwrite RespondMissingFileChoice = "overwrite"
+)
+
+type RespondMissingFileRequest struct {
+ Choice RespondMissingFileChoice `json:"choice"`
+ ModelStreamId string `json:"modelStreamId"`
+ FilePath string `json:"filePath"`
+ Body string `json:"body"`
+}
+
type LoadContextParams struct {
ContextType ContextType `json:"contextType"`
Name string `json:"name"`
diff --git a/app/shared/stream.go b/app/shared/stream.go
index c6ea3c1f..63167372 100644
--- a/app/shared/stream.go
+++ b/app/shared/stream.go
@@ -11,20 +11,24 @@ type BuildInfo struct {
type StreamMessageType string
const (
- StreamMessageReply StreamMessageType = "reply"
- StreamMessageDescribing StreamMessageType = "describing"
- StreamMessageDescription StreamMessageType = "description"
- StreamMessageBuildInfo StreamMessageType = "buildInfo"
- StreamMessageAborted StreamMessageType = "aborted"
- StreamMessageFinished StreamMessageType = "finished"
- StreamMessageError StreamMessageType = "error"
+ StreamMessageReply StreamMessageType = "reply"
+ StreamMessageDescribing StreamMessageType = "describing"
+ StreamMessageDescription StreamMessageType = "description"
+ StreamMessageBuildInfo StreamMessageType = "buildInfo"
+ StreamMessagePromptMissingFile StreamMessageType = "promptMissingFile"
+ StreamMessageAborted StreamMessageType = "aborted"
+ StreamMessageFinished StreamMessageType = "finished"
+ StreamMessageError StreamMessageType = "error"
)
type StreamMessage struct {
Type StreamMessageType `json:"type"`
- ReplyChunk string `json:"replyChunk,omitempty"`
- BuildInfo *BuildInfo `json:"planTokenCount,omitempty"`
- Description *ConvoMessageDescription `json:"description,omitempty"`
- Error *ApiError `json:"error,omitempty"`
+ ReplyChunk string `json:"replyChunk,omitempty"`
+
+ BuildInfo *BuildInfo `json:"planTokenCount,omitempty"`
+ Description *ConvoMessageDescription `json:"description,omitempty"`
+ Error *ApiError `json:"error,omitempty"`
+ MissingFilePath string `json:"missingFilePath,omitempty"`
+ ModelStreamId string `json:"modelStreamId,omitempty"`
}