Skip to content

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

continuing work on auto-continue/build queue + cleaning up rbac a bit

Dane Schneider041cf859dfeb
diff --git a/app/cli/api/stream.go b/app/cli/api/stream.go
index 92fd25dd..5404d7f5 100644
--- a/app/cli/api/stream.go
+++ b/app/cli/api/stream.go
@@ -3,7 +3,7 @@ package api
import (
"bufio"
"bytes"
- "context"
+ "encoding/json"
"io"
"log"
"plandex/types"
@@ -12,7 +12,6 @@ import (
)
func connectPlanRespStream(body io.ReadCloser, onStream types.OnStreamPlan) {
- streamState := shared.NewPlanStreamState()
reader := bufio.NewReader(body)
go func() {
@@ -20,44 +19,22 @@ func connectPlanRespStream(body io.ReadCloser, onStream types.OnStreamPlan) {
s, err := readUntilSeparator(reader, shared.STREAM_MESSAGE_SEPARATOR)
if err != nil {
log.Println("Error reading line:", err)
- streamState.Event(context.Background(), shared.EVENT_ERROR)
- onStream(types.OnStreamPlanParams{Content: "", State: streamState, Err: err})
+ onStream(types.OnStreamPlanParams{Msg: nil, Err: err})
body.Close()
return
}
- // log.Println("Stream received:", s)
-
- if s == shared.STREAM_FINISHED || s == shared.STREAM_ABORTED {
- var evt string
- if s == shared.STREAM_FINISHED {
- evt = shared.EVENT_FINISH
- } else {
- evt = shared.STATE_ABORTED
- }
- err := streamState.Event(context.Background(), evt)
- if err != nil {
- log.Printf("Error triggering state change %s: %s\n", evt, err)
- }
- onStream(types.OnStreamPlanParams{Content: "", State: streamState, Err: err})
- body.Close()
- return
- }
-
- if s == shared.STREAM_DESCRIPTION_PHASE {
- err = streamState.Event(context.Background(), shared.EVENT_DESCRIBE)
- } else if s == shared.STREAM_BUILD_PHASE {
- err = streamState.Event(context.Background(), shared.EVENT_BUILD)
- }
-
+ var msg shared.StreamMessage
+ err = json.Unmarshal([]byte(s), &msg)
if err != nil {
- log.Println("Error setting state:", err)
- onStream(types.OnStreamPlanParams{Content: "", State: streamState, Err: err})
+ log.Println("Error unmarshalling message:", err)
+ onStream(types.OnStreamPlanParams{Msg: nil, Err: err})
body.Close()
return
}
- onStream(types.OnStreamPlanParams{Content: s, State: streamState, Err: nil})
+ onStream(types.OnStreamPlanParams{Msg: &msg, Err: nil})
+ body.Close()
}
}()
}
diff --git a/app/cli/lib/stream.go b/app/cli/lib/stream.go
index 6331fcd9..973d3a95 100644
--- a/app/cli/lib/stream.go
+++ b/app/cli/lib/stream.go
@@ -1,35 +1,16 @@
package lib
import (
- "encoding/json"
"log"
streamtui "plandex/stream_tui"
"plandex/types"
-
- "github.com/plandex/plandex/shared"
)
var OnStreamPlan types.OnStreamPlan = func(params types.OnStreamPlanParams) {
- switch params.State.Current() {
- case shared.STATE_REPLYING:
- streamtui.Send(types.StreamTUIUpdate{
- ReplyChunk: params.Content,
- })
- case shared.STATE_DESCRIBING:
- streamtui.Send(types.StreamTUIUpdate{
- Processing: true,
- })
-
- case shared.STATE_BUILDING:
- var tokenCount shared.PlanTokenCount
- err := json.Unmarshal([]byte(params.Content), &tokenCount)
- if err != nil {
- log.Println("error parsing plan token count update:", err)
- return
- }
- streamtui.Send(types.StreamTUIUpdate{
- PlanTokenCount: &tokenCount,
- })
+ if params.Err != nil {
+ log.Println("Error in stream:", params.Err)
+ return
}
+ streamtui.Send(params.Msg)
}
diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.go
index 3d8f9da3..16908a1e 100644
--- a/app/cli/stream_tui/update.go
+++ b/app/cli/stream_tui/update.go
@@ -2,13 +2,13 @@ package streamtui
import (
"plandex/term"
- "plandex/types"
bubbleKey "github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/plandex/plandex/shared"
)
func (m *streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -24,7 +24,7 @@ func (m *streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.windowResized(msg.Width, msg.Height)
- case types.StreamTUIUpdate:
+ case shared.StreamMessage:
return m.streamUpdate(&msg)
case tea.KeyMsg:
@@ -124,23 +124,29 @@ func (m *streamUIModel) pageUp() {
}
}
-func (m *streamUIModel) streamUpdate(msg *types.StreamTUIUpdate) (tea.Model, tea.Cmd) {
- if msg.PlanTokenCount != nil {
- m.processing = false
- m.building = true
-
- m.tokensByPath[msg.PlanTokenCount.Path] += msg.PlanTokenCount.NumTokens
- if msg.PlanTokenCount.Finished {
- m.finishedByPath[msg.PlanTokenCount.Path] = true
- }
- } else if msg.ReplyChunk != "" {
+func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage) (tea.Model, tea.Cmd) {
+ switch msg.Type {
+ case shared.StreamMessageReply:
m.processing = false
m.reply += msg.ReplyChunk
m.updateReplyDisplay()
- } else if msg.Processing {
+ case shared.StreamMessageBuildInfo:
+ m.building = true
+ m.tokensByPath[msg.BuildInfo.Path] += msg.BuildInfo.NumTokens
+ if msg.BuildInfo.Finished {
+ m.finishedByPath[msg.BuildInfo.Path] = true
+ }
+
+ case shared.StreamMessageDescribing:
m.processing = true
return m, m.spinner.Tick
+
+ case shared.StreamMessageError:
+
+ case shared.StreamMessageFinished:
+
+ case shared.StreamMessageAborted:
}
return m, nil
diff --git a/app/cli/types/api.go b/app/cli/types/api.go
index 17940660..549f24c2 100644
--- a/app/cli/types/api.go
+++ b/app/cli/types/api.go
@@ -1,14 +1,12 @@
package types
import (
- "github.com/looplab/fsm"
"github.com/plandex/plandex/shared"
)
type OnStreamPlanParams struct {
- Content string
- State *fsm.FSM
- Err error
+ Msg *shared.StreamMessage
+ Err error
}
type OnStreamPlan func(params OnStreamPlanParams)
diff --git a/app/cli/types/types.go b/app/cli/types/types.go
index a5d7129a..364e63d5 100644
--- a/app/cli/types/types.go
+++ b/app/cli/types/types.go
@@ -49,12 +49,6 @@ type ProjectSettings struct {
Id string `json:"id"`
}
-type StreamTUIUpdate struct {
- ReplyChunk string
- Processing bool
- PlanTokenCount *shared.PlanTokenCount
-}
-
type ChangesUIScrollReplacement struct {
OldContent string
NewContent string
diff --git a/app/server/handlers/auth_helpers.go b/app/server/handlers/auth_helpers.go
index 8b818dd6..d3b7007c 100644
--- a/app/server/handlers/auth_helpers.go
+++ b/app/server/handlers/auth_helpers.go
@@ -131,9 +131,9 @@ func authenticate(w http.ResponseWriter, r *http.Request, requireOrg bool) *type
}
// build the permissions map
- permissionsMap := make(map[string]bool)
+ permissionsMap := make(map[types.Permission]bool)
for _, permission := range permissions {
- permissionsMap[permission] = true
+ permissionsMap[types.Permission(permission)] = true
}
return &types.ServerAuth{
@@ -170,7 +170,7 @@ func authorizeProjectRename(w http.ResponseWriter, projectId string, auth *types
return false
}
- if !auth.HasPermission("rename_any_project") {
+ if !auth.HasPermission(types.PermissionRenameAnyProject) {
log.Println("User does not have permission to rename project")
http.Error(w, "User does not have permission to rename project", http.StatusForbidden)
return false
@@ -184,7 +184,7 @@ func authorizeProjectDelete(w http.ResponseWriter, projectId string, auth *types
return false
}
- if !auth.HasPermission("delete_any_project") {
+ if !auth.HasPermission(types.PermissionDeleteAnyProject) {
log.Println("User does not have permission to delete project")
http.Error(w, "User does not have permission to delete project", http.StatusForbidden)
return false
@@ -220,7 +220,7 @@ func authorizePlanUpdate(w http.ResponseWriter, planId string, auth *types.Serve
return nil
}
- if plan.OwnerId != auth.User.Id && !auth.HasPermission("update_any_plan") {
+ if plan.OwnerId != auth.User.Id && !auth.HasPermission(types.PermissionUpdateAnyPlan) {
log.Println("User does not have permission to update plan")
http.Error(w, "User does not have permission to update plan", http.StatusForbidden)
return nil
@@ -236,7 +236,7 @@ func authorizePlanDelete(w http.ResponseWriter, planId string, auth *types.Serve
return nil
}
- if plan.OwnerId != auth.User.Id && !auth.HasPermission("delete_any_plan") {
+ if plan.OwnerId != auth.User.Id && !auth.HasPermission(types.PermissionDeleteAnyPlan) {
log.Println("User does not have permission to delete plan")
http.Error(w, "User does not have permission to delete plan", http.StatusForbidden)
return nil
@@ -252,7 +252,7 @@ func authorizePlanRename(w http.ResponseWriter, planId string, auth *types.Serve
return nil
}
- if plan.OwnerId != auth.User.Id && !auth.HasPermission("rename_any_plan") {
+ if plan.OwnerId != auth.User.Id && !auth.HasPermission(types.PermissionRenameAnyPlan) {
log.Println("User does not have permission to rename plan")
http.Error(w, "User does not have permission to rename plan", http.StatusForbidden)
return nil
@@ -268,7 +268,7 @@ func authorizePlanArchive(w http.ResponseWriter, planId string, auth *types.Serv
return nil
}
- if plan.OwnerId != auth.User.Id && !auth.HasPermission("archive_any_plan") {
+ if plan.OwnerId != auth.User.Id && !auth.HasPermission(types.PermissionArchiveAnyPlan) {
log.Println("User does not have permission to archive plan")
http.Error(w, "User does not have permission to archive plan", http.StatusForbidden)
return nil
diff --git a/app/server/handlers/invites.go b/app/server/handlers/invites.go
index c29be4f4..c387ee38 100644
--- a/app/server/handlers/invites.go
+++ b/app/server/handlers/invites.go
@@ -5,6 +5,7 @@ import (
"log"
"net/http"
"plandex-server/db"
+ "plandex-server/types"
"strings"
"github.com/gorilla/mux"
@@ -40,7 +41,9 @@ func InviteUserHandler(w http.ResponseWriter, r *http.Request) {
req.Email = strings.ToLower(req.Email)
// ensure current user can invite target user
- if !auth.HasPermission(strings.Join([]string{"invite_user", req.OrgRoleId}, "|")) {
+ permission := types.Permission(strings.Join([]string{string(types.PermissionInviteUser), req.OrgRoleId}, "|"))
+
+ if !auth.HasPermission(permission) {
log.Printf("User does not have permission to invite user with role: %v\n", req.OrgRoleId)
http.Error(w, "User does not have permission to invite user with role: "+req.OrgRoleId, http.StatusForbidden)
return
@@ -281,8 +284,12 @@ func DeleteInviteHandler(w http.ResponseWriter, r *http.Request) {
}
// ensure current user can remove target invite
- if !(auth.HasPermission(strings.Join([]string{"remove_user", invite.OrgRoleId}, "|")) ||
- (auth.User.Id == invite.InviterId && auth.HasPermission(strings.Join([]string{"invite_user", invite.OrgRoleId}, "|")))) {
+ removePermission := types.Permission(strings.Join([]string{string(types.PermissionRemoveUser), invite.OrgRoleId}, "|"))
+
+ invitePermission := types.Permission(strings.Join([]string{string(types.PermissionInviteUser), invite.OrgRoleId}, "|"))
+
+ if !(auth.HasPermission(removePermission) ||
+ (auth.User.Id == invite.InviterId && auth.HasPermission(invitePermission))) {
log.Printf("User does not have permission to remove invite with role: %v\n", invite.OrgRoleId)
http.Error(w, "User does not have permission to remove invite with role: "+invite.OrgRoleId, http.StatusForbidden)
return
diff --git a/app/server/handlers/orgs.go b/app/server/handlers/orgs.go
index aa591291..3a1bb1dd 100644
--- a/app/server/handlers/orgs.go
+++ b/app/server/handlers/orgs.go
@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"plandex-server/db"
+ "plandex-server/types"
"github.com/plandex/plandex/shared"
)
@@ -168,7 +169,7 @@ func ListOrgRolesHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if !auth.HasPermission("list_org_roles") {
+ if !auth.HasPermission(types.PermissionListOrgRoles) {
log.Println("User cannot list org roles")
http.Error(w, "User cannot list org roles", http.StatusForbidden)
return
diff --git a/app/server/handlers/plans_crud.go b/app/server/handlers/plans_crud.go
index ca61926f..5ba73190 100644
--- a/app/server/handlers/plans_crud.go
+++ b/app/server/handlers/plans_crud.go
@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"plandex-server/db"
+ "plandex-server/types"
"github.com/gorilla/mux"
"github.com/plandex/plandex/shared"
@@ -23,7 +24,7 @@ func CreatePlanHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if !auth.HasPermission("create_plan") {
+ if !auth.HasPermission(types.PermissionCreatePlan) {
log.Println("User does not have permission to create a plan")
http.Error(w, "User does not have permission to create a plan", http.StatusForbidden)
return
diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.go
index 02960a70..0cd7b235 100644
--- a/app/server/handlers/plans_exec.go
+++ b/app/server/handlers/plans_exec.go
@@ -8,6 +8,7 @@ import (
"os"
"plandex-server/db"
model "plandex-server/model/plan"
+ "plandex-server/types"
"github.com/gorilla/mux"
"github.com/plandex/plandex/shared"
@@ -34,7 +35,7 @@ func TellPlanHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if plan.OwnerId != auth.User.Id && !auth.HasPermission("update_any_plan") {
+ if plan.OwnerId != auth.User.Id && !auth.HasPermission(types.PermissionUpdateAnyPlan) {
log.Println("User does not have permission to update plan")
http.Error(w, "User does not have permission to update plan", http.StatusForbidden)
return
diff --git a/app/server/handlers/users.go b/app/server/handlers/users.go
index f8205367..2370ea75 100644
--- a/app/server/handlers/users.go
+++ b/app/server/handlers/users.go
@@ -5,6 +5,7 @@ import (
"log"
"net/http"
"plandex-server/db"
+ "plandex-server/types"
"strings"
"github.com/gorilla/mux"
@@ -74,7 +75,9 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {
}
// ensure current user can invite target user
- if !auth.HasPermission(strings.Join([]string{"remove_user", user.OrgRoleId}, "|")) {
+ removePermission := types.Permission(strings.Join([]string{string(types.PermissionRemoveUser), user.OrgRoleId}, "|"))
+
+ if !auth.HasPermission(removePermission) {
log.Printf("User does not have permission to invite user with role: %v\n", user.OrgRoleId)
http.Error(w, "User does not have permission to invite user with role: "+user.OrgRoleId, http.StatusForbidden)
return
diff --git a/app/server/migrations/2023120500_init.up.sql b/app/server/migrations/2023120500_init.up.sql
index 31f730a5..fa2eeead 100644
--- a/app/server/migrations/2023120500_init.up.sql
+++ b/app/server/migrations/2023120500_init.up.sql
@@ -151,7 +151,6 @@ CREATE TABLE IF NOT EXISTS plan_builds (
convo_message_id UUID NOT NULL,
file_path VARCHAR(255) NOT NULL,
error TEXT,
- finished_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
diff --git a/app/server/model/plan/build.go b/app/server/model/plan/build.go
index 34d6984f..d940c002 100644
--- a/app/server/model/plan/build.go
+++ b/app/server/model/plan/build.go
@@ -23,43 +23,21 @@ import (
const MaxRetries = 3
const MaxReplacementRetries = 1
-// func BuildPlan(currentOrgId, planId string) *types.ActivePlan {
-// log.Printf("Building plan: %s\n", planId)
-
-// // goEnv := os.Getenv("GOENV")
-// // if goEnv == "test" {
-// // streamFilesLoremIpsum(onStream)
-// // return nil
-// // }
-
-// active := Active.Get(planId)
-
-// if active == nil {
-// log.Printf("Active plan not found for plan %s\n", planId)
-// // TODO: to allow for rebuilds or selective builds, construct the active plan here from the db
-// } else {
-// for _, filePath := range active.Files {
-// go execPlanBuild(currentOrgId, filePath, active)
-// }
-// }
-
-// return active
-// }
-
func QueueBuild(currentOrgId, planId string, activeBuild *types.ActiveBuild) {
activePlan := Active.Get(planId)
filePath := activeBuild.Path
+ Active.Update(planId, func(active *types.ActivePlan) {
+ active.BuildQueuesByPath[filePath] = append(active.BuildQueuesByPath[filePath], activeBuild)
+ })
+ log.Printf("Queued build for file %s\n", filePath)
+
if !activePlan.PathFinished(filePath) {
log.Printf("Already building file %s\n", filePath)
return
} else {
-
- Active.Update(planId, func(active *types.ActivePlan) {
- active.BuildQueuesByPath[filePath] = append(active.BuildQueuesByPath[filePath])
- })
-
- execPlanBuild(currentOrgId, activePlan, activeBuild)
+ log.Printf("Will process build queue for file %s\n", filePath)
+ go execPlanBuild(currentOrgId, activePlan, activeBuild)
}
}
@@ -67,22 +45,19 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
planId := activePlan.Id
filePath := activeBuild.Path
- tokenCount := &shared.PlanTokenCount{
+ buildInfo := &shared.BuildInfo{
Path: filePath,
NumTokens: 0,
Finished: false,
}
- tokenCountJson, err := json.Marshal(tokenCount)
- if err != nil {
- log.Printf("Error marshalling plan token count: %v\n", err)
- activePlan.StreamDoneCh <- err
- return
- }
- activePlan.StreamCh <- string(tokenCountJson)
+ activePlan.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageBuildInfo,
+ BuildInfo: buildInfo,
+ })
replyInfo := types.NewReplyParser()
replyInfo.AddToken(activePlan.CurrentReplyContent, true)
- _, fileContents, numTokensByFile, _ := replyInfo.Read()
+ _, fileContents, _, _ := replyInfo.Read()
errCh := make(chan error)
@@ -140,8 +115,8 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
onFinishBuild := func() {
log.Println("Build finished.")
- activePlan.StreamCh <- shared.STREAM_FINISHED
- activePlan.StreamDoneCh <- nil
+ // activePlan.StreamCh <- shared.STREAM_FINISHED
+ // activePlan.StreamDoneCh <- nil
}
onFinishBuildFile := func(filePath string, planRes *db.PlanFileResult) {
@@ -157,6 +132,8 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
return
}
+ activeBuild.Success = true
+
Active.Update(planId, func(ap *types.ActivePlan) {
ap.BuiltFiles[filePath] = true
@@ -175,6 +152,8 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
onBuildFileError := func(filePath string, err error) {
log.Printf("Error for file %s: %v\n", filePath, err)
+ activeBuild.Error = err
+
activePlan.StreamDoneCh <- err
if err != nil {
@@ -212,19 +191,16 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
if currentState == "" {
log.Printf("File %s not found in model context or current plan. Creating new file.\n", filePath)
- planTokenCount := &shared.PlanTokenCount{
+ buildInfo := &shared.BuildInfo{
Path: filePath,
- NumTokens: numTokensByFile[filePath],
+ NumTokens: 0,
Finished: true,
}
- // log.Printf("%s: %s", filePath, content)
- planTokenCountJson, err := json.Marshal(planTokenCount)
- if err != nil {
- onBuildFileError(filePath, fmt.Errorf("error marshalling plan chunk: %v", err))
- return
- }
- activePlan.StreamCh <- string(planTokenCountJson)
+ activePlan.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageBuildInfo,
+ BuildInfo: buildInfo,
+ })
// new file
planRes := &db.PlanFileResult{
@@ -295,12 +271,12 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
// }
modelReq := openai.ChatCompletionRequest{
- Model: model.BuilderModel,
- Functions: []openai.FunctionDefinition{prompts.ReplaceFn},
- Messages: fileMessages,
- Temperature: 0.2,
- TopP: 0.1,
- // ResponseFormat: &openai.ChatCompletionResponseFormat{Type: "json_object"},
+ Model: model.BuilderModel,
+ Functions: []openai.FunctionDefinition{prompts.ReplaceFn},
+ Messages: fileMessages,
+ Temperature: 0.2,
+ TopP: 0.1,
+ ResponseFormat: &openai.ChatCompletionResponseFormat{Type: "json_object"},
}
stream, err := model.Client.CreateChatCompletionStream(activePlan.Ctx, modelReq)
@@ -437,19 +413,17 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
content = delta.FunctionCall.Arguments
}
- planTokenCount := &shared.PlanTokenCount{
+ buildInfo := &shared.BuildInfo{
Path: filePath,
NumTokens: 1,
Finished: false,
}
// log.Printf("%s: %s", filePath, content)
- planTokenCountJson, err := json.Marshal(planTokenCount)
- if err != nil {
- onBuildFileError(filePath, fmt.Errorf("error marshalling plan chunk: %v", err))
- return
- }
- activePlan.StreamCh <- string(planTokenCountJson)
+ activePlan.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageBuildInfo,
+ BuildInfo: buildInfo,
+ })
activeBuild.Buffer += content
@@ -492,19 +466,15 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
}
}
- planTokenCount := &shared.PlanTokenCount{
+ buildInfo := &shared.BuildInfo{
Path: filePath,
NumTokens: 0,
Finished: true,
}
-
- // log.Printf("%s: %s", filePath, content)
- planTokenCountJson, err := json.Marshal(planTokenCount)
- if err != nil {
- onBuildFileError(filePath, fmt.Errorf("error marshalling plan chunk: %v", err))
- return
- }
- activePlan.StreamCh <- string(planTokenCountJson)
+ activePlan.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageBuildInfo,
+ BuildInfo: buildInfo,
+ })
onFinishBuildFile(filePath, planFileResult)
return
@@ -514,9 +484,7 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuil
}()
}
- for _, filePath := range activePlan.Files {
- go buildFile(filePath, 0, 0, nil)
- }
+ buildFile(filePath, 0, 0, nil)
}
type planResultParams struct {
diff --git a/app/server/model/plan/lorem_ipsum.go b/app/server/model/plan/lorem_ipsum.go
index c16c6cdb..8bfb87c7 100644
--- a/app/server/model/plan/lorem_ipsum.go
+++ b/app/server/model/plan/lorem_ipsum.go
@@ -70,7 +70,7 @@ package plan
// func streamFilesLoremIpsum(onStream types.OnStreamFunc) {
// writeNumTokens := func(filePath string, content string) {
// numTokens := shared.GetNumTokens(content)
-// chunk := shared.PlanTokenCount{Path: filePath, NumTokens: numTokens}
+// chunk := shared.BuildInfo{Path: filePath, NumTokens: numTokens}
// chunkJson, _ := json.Marshal(chunk)
// onStream(string(chunkJson), nil)
// time.Sleep(50 * time.Millisecond) // Adding a small delay between files for effect
diff --git a/app/server/model/plan/tell.go b/app/server/model/plan/tell.go
index bb5abd32..1822fba8 100644
--- a/app/server/model/plan/tell.go
+++ b/app/server/model/plan/tell.go
@@ -21,7 +21,7 @@ import (
// Proposal function to create a new proposal
func Tell(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanRequest) error {
- // goEnv := os.Getenv("GOENV") // Fetch the GO_ENV environment variable
+ // goEnv := os.Getenv("GOENV") // Fetch the GOENV environment variable
// log.Println("GOENV: " + goEnv)
// if goEnv == "test" {
@@ -459,7 +459,10 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq
choice := response.Choices[0]
if choice.FinishReason != "" {
- active.StreamCh <- shared.STREAM_DESCRIPTION_PHASE
+ active.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageDescribing,
+ })
+
err := db.SetPlanStatus(planId, shared.PlanStatusDescribing, "")
if err != nil {
onError(fmt.Errorf("failed to set plan status to describing: %v", err), true, "", "")
@@ -551,16 +554,18 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq
}
if !req.AutoContinue || execStatus.Finished || execStatus.NeedsInput {
- active.StreamCh <- shared.STREAM_FINISHED
+ active.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageFinished,
+ })
active.StreamDoneCh <- nil
-
- return
} else {
+ // TODO: validate that user can continue plan
// continue plan
-
+ execTellPlan(plan, auth, req, active)
}
+ return
}
delta := choice.Delta
@@ -571,7 +576,10 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq
})
// log.Printf("%s", content)
- active.StreamCh <- content
+ active.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageReply,
+ ReplyChunk: content,
+ })
replyParser.AddToken(content, true)
files, _, _, numTokens := replyParser.Read()
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index 2d13db6a..199bc8dc 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -2,26 +2,26 @@ package types
import (
"context"
+ "encoding/json"
"plandex-server/db"
"github.com/google/uuid"
+ "github.com/plandex/plandex/shared"
)
type ActiveBuild struct {
AssistantMessageId string
ReplyContent string
+ FileContent string
Path string
Buffer string
Success bool
Error error
- ErrorReason string
}
type ActivePlan struct {
Id string
Prompt string
- StreamCh chan string
- StreamDoneCh chan error
Ctx context.Context
CancelFn context.CancelFunc
Contexts []*db.Context
@@ -32,7 +32,10 @@ type ActivePlan struct {
NumTokens int
PromptMessageNum int
BuildQueuesByPath map[string][]*ActiveBuild
- subscriptions map[string]chan string
+ StreamDoneCh chan error
+
+ streamCh chan string
+ subscriptions map[string]chan string
}
func NewActivePlan(planId, prompt string) *ActivePlan {
@@ -41,8 +44,6 @@ func NewActivePlan(planId, prompt string) *ActivePlan {
active := ActivePlan{
Id: planId,
Prompt: prompt,
- StreamCh: make(chan string),
- StreamDoneCh: make(chan error),
Ctx: ctx,
CancelFn: cancel,
BuildQueuesByPath: map[string][]*ActiveBuild{},
@@ -50,7 +51,10 @@ func NewActivePlan(planId, prompt string) *ActivePlan {
ContextsByPath: map[string]*db.Context{},
Files: []string{},
BuiltFiles: map[string]bool{},
- subscriptions: map[string]chan string{},
+
+ streamCh: make(chan string),
+ StreamDoneCh: make(chan error),
+ subscriptions: map[string]chan string{},
}
go func() {
@@ -58,7 +62,7 @@ func NewActivePlan(planId, prompt string) *ActivePlan {
select {
case <-active.Ctx.Done():
return
- case msg := <-active.StreamCh:
+ case msg := <-active.streamCh:
for _, ch := range active.subscriptions {
ch <- msg
}
@@ -69,8 +73,13 @@ func NewActivePlan(planId, prompt string) *ActivePlan {
return &active
}
-func (b *ActiveBuild) BuildFinished() bool {
- return b.Success || b.Error != nil
+func (ap *ActivePlan) Stream(msg shared.StreamMessage) {
+ msgJson, err := json.Marshal(msg)
+ if err != nil {
+ ap.StreamDoneCh <- err
+ return
+ }
+ ap.streamCh <- string(msgJson)
}
func (ap *ActivePlan) BuildFinished() bool {
@@ -101,3 +110,7 @@ func (ap *ActivePlan) Subscribe() (string, chan string) {
func (ap *ActivePlan) Unsubscribe(id string) {
delete(ap.subscriptions, id)
}
+
+func (b *ActiveBuild) BuildFinished() bool {
+ return b.Success || b.Error != nil
+}
diff --git a/app/server/types/auth.go b/app/server/types/auth.go
index 5b4dd530..a87a5daa 100644
--- a/app/server/types/auth.go
+++ b/app/server/types/auth.go
@@ -6,13 +6,34 @@ type ServerAuth struct {
AuthToken *db.AuthToken
User *db.User
OrgId string
- Permissions map[string]bool
+ Permissions map[Permission]bool
}
-func (a *ServerAuth) HasPermission(permission string) bool {
+func (a *ServerAuth) HasPermission(permission Permission) bool {
if a.Permissions == nil {
return false
}
return a.Permissions[permission]
}
+
+type Permission string
+
+const (
+ PermissionDeleteOrg Permission = "delete_org"
+ PermissionManageEmailDomainAuth Permission = "manage_email_domain_auth"
+ PermissionManageBilling Permission = "manage_billing"
+ PermissionInviteUser Permission = "invite_user"
+ PermissionRemoveUser Permission = "remove_user"
+ PermissionSetUserRole Permission = "set_user_role"
+ PermissionListOrgRoles Permission = "list_org_roles"
+ PermissionCreateProject Permission = "create_project"
+ PermissionRenameAnyProject Permission = "rename_any_project"
+ PermissionDeleteAnyProject Permission = "delete_any_project"
+ PermissionCreatePlan Permission = "create_plan"
+ PermissionManageAnyPlanShares Permission = "manage_any_plan_shares"
+ PermissionRenameAnyPlan Permission = "rename_any_plan"
+ PermissionDeleteAnyPlan Permission = "delete_any_plan"
+ PermissionUpdateAnyPlan Permission = "update_any_plan"
+ PermissionArchiveAnyPlan Permission = "archive_any_plan"
+)
diff --git a/app/server/types/exec_status.go b/app/server/types/exec_status.go
new file mode 100644
index 00000000..eefd66a1
--- /dev/null
+++ b/app/server/types/exec_status.go
@@ -0,0 +1,6 @@
+package types
+
+type PlanExecStatus struct {
+ NeedsInput bool `json:"needsInput"`
+ Finished bool `json:"finished"`
+}
diff --git a/app/shared/stream.go b/app/shared/stream.go
index 087551d8..a8f21156 100644
--- a/app/shared/stream.go
+++ b/app/shared/stream.go
@@ -1,52 +1,30 @@
package shared
-import "github.com/looplab/fsm"
-
const STREAM_MESSAGE_SEPARATOR = "@@PX@@"
-const STREAM_FINISHED = "@@PXEND@@"
-const STREAM_DESCRIPTION_PHASE = "@@PXDESC@@"
-const STREAM_RESUME = "@@PXRESUME@@"
-const STREAM_ABORTED = "@@PXABORT@@"
-
-const EVENT_DESCRIBE = "describe"
-const EVENT_FINISH = "finish"
-const EVENT_RESUME = "resume"
-const EVENT_ABORT = "abort"
-const EVENT_CANCEL = "cancel"
-const EVENT_ERROR = "error"
-
-const STATE_REPLYING = "replying"
-const STATE_DESCRIBING = "describing"
-const STATE_FINISHED = "finished"
-const STATE_ABORTED = "aborted"
-const STATE_CANCELED = "canceled"
-const STATE_ERROR = "error"
-
-func NewPlanStreamState() *fsm.FSM {
- sm := fsm.NewFSM(
- STATE_REPLYING,
- fsm.Events{
- // Define state transitions
- {Name: EVENT_DESCRIBE, Src: []string{STATE_REPLYING}, Dst: STATE_DESCRIBING},
-
- {Name: EVENT_RESUME, Src: []string{STATE_DESCRIBING}, Dst: STATE_REPLYING},
-
- {Name: EVENT_FINISH, Src: []string{STATE_DESCRIBING}, Dst: STATE_FINISHED},
-
- {Name: EVENT_ABORT, Src: []string{STATE_REPLYING, STATE_DESCRIBING}, Dst: STATE_ABORTED},
- {Name: EVENT_CANCEL, Src: []string{STATE_ABORTED}, Dst: STATE_CANCELED},
-
- {Name: EVENT_ERROR, Src: []string{STATE_REPLYING, STATE_DESCRIBING}},
- },
- fsm.Callbacks{},
- )
-
- return sm
-}
-
-type PlanTokenCount struct {
+type BuildInfo struct {
Path string `json:"path"`
NumTokens int `json:"numTokens"`
Finished bool `json:"finished"`
}
+
+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"
+)
+
+type StreamMessage struct {
+ Type StreamMessageType `json:"type"`
+
+ ReplyChunk string `json:"replyChunk,omitempty"`
+ BuildInfo *BuildInfo `json:"planTokenCount,omitempty"`
+ Description *ConvoMessageDescription `json:"description,omitempty"`
+ Error string `json:"error,omitempty"`
+}
diff --git a/test_prompts/aws-infra.txt b/test_prompts/aws-infra.txt
new file mode 100644
index 00000000..66027269
--- /dev/null
+++ b/test_prompts/aws-infra.txt
@@ -0,0 +1,33 @@
+I want to deploy api infrastructure with the following components:
+
+ These should all be done with the AWS CDK and tied together in
+ infra/lib/main.ts
+
+ Please pay close attention to detail and ensure every setting is correct,
+ secure, and production ready. At the same time, do not include any
+ nonessential attributes or complexity. Keep it as simple as it can be while
+ still being correct.
+
+ • A basic VPC
+ • Two public subnets that allow outgoing requests
+ • Two private subnets for the database
+ • An RDS Aurora postgresql database with smallest possible size--just a single
+ instance with no replicas for now. it should run in the private subnets.
+ • An ECR repository where container images can be stored that are loaded by
+ the fargate cluster
+ • A fargate ECS cluster that runs an image from the ECR repository. just one
+ replica in the cluster for now
+ • The fargate cluster should have access to the RDS database. the cluster
+ should run in public subnets that can make outgoing requests to the
+ internet.
+ • Replicas within the fargate cluster should be able to make requests to
+ each other internally- The fargate cluster and RDS should use a secrets
+ manager secret for the database credentials.
+ • I need an EFS shared file system that all the fargate cluster containers
+ are connected to
+ • The fargate containers also need to send emails via SES... please include
+ any necessary resources
+
+ please use your best judgement and select reasonable values for all of
+ these. the db password should be generated by secrets manager. use defaults
+ and best practices.