Skip to content

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

convo message flags and subtask storage. better log messages. better stage resolution based on last convo message

Dane Schneider6b4b7e667ba2
diff --git a/app/cli/cmd/convo.go b/app/cli/cmd/convo.go
index c2b90859..c6e2ee1a 100644
--- a/app/cli/cmd/convo.go
+++ b/app/cli/cmd/convo.go
@@ -10,8 +10,6 @@ import (
"strings"
"time"
- shared "plandex-shared"
-
"github.com/fatih/color"
"github.com/spf13/cobra"
)
@@ -105,14 +103,7 @@ func convo(cmd *cobra.Command, args []string) {
author = msg.Role
}
- var replyType string
- if msg.ReplyType == shared.ReplyTypeLoadedContext {
- replyType = "πŸ“₯ Loaded Context"
- } else if msg.ReplyType == shared.ReplyTypeMadePlan {
- replyType = "πŸ“‹ Made Plan"
- } else if msg.ReplyType == shared.ReplyTypeImplementation {
- replyType = "πŸ‘¨β€πŸ’» Wrote Code"
- }
+ replyTags := msg.Flags.GetReplyTags()
// format as above but start with day of week
formattedTs := msg.CreatedAt.Local().Format("Mon Jan 2, 2006 | 3:04pm MST")
@@ -128,9 +119,9 @@ func convo(cmd *cobra.Command, args []string) {
}
var header string
- if replyType != "" {
+ if len(replyTags) > 0 {
header = fmt.Sprintf("#### %d | %s | %s | %s | %d πŸͺ™ ", i+1,
- author, replyType, formattedTs, msg.Tokens)
+ author, strings.Join(replyTags, " | "), formattedTs, msg.Tokens)
} else {
header = fmt.Sprintf("#### %d | %s | %s | %d πŸͺ™ ", i+1,
author, formattedTs, msg.Tokens)
diff --git a/app/server/db/convo_helpers.go b/app/server/db/convo_helpers.go
index f73eec6a..3754ec94 100644
--- a/app/server/db/convo_helpers.go
+++ b/app/server/db/convo_helpers.go
@@ -6,10 +6,9 @@ import (
"os"
"path/filepath"
"sort"
+ "strings"
"time"
- shared "plandex-shared"
-
"github.com/fatih/color"
"github.com/google/uuid"
"github.com/sashabaranov/go-openai"
@@ -134,22 +133,35 @@ func StoreConvoMessage(message *ConvoMessage, currentUserId, branch string, comm
}
}
- var replyType string
- if message.ReplyType == shared.ReplyTypeLoadedContext {
- replyType = "πŸ“₯ Loaded Context"
- } else if message.ReplyType == shared.ReplyTypeMadePlan {
- replyType = "πŸ“‹ Made Plan"
- } else if message.ReplyType == shared.ReplyTypeImplementation {
- replyType = "πŸ‘¨β€πŸ’» Wrote Code"
- }
+ replyTags := message.Flags.GetReplyTags()
var msg string
- if replyType != "" {
- msg = fmt.Sprintf("Message #%d | %s | %s | %d πŸͺ™", message.Num, desc, replyType, message.Tokens)
+ if len(replyTags) > 0 {
+ msg = fmt.Sprintf("Message #%d | %s | %s | %d πŸͺ™", message.Num, desc, strings.Join(replyTags, " | "), message.Tokens)
} else {
msg = fmt.Sprintf("Message #%d | %s | %d πŸͺ™", message.Num, desc, message.Tokens)
}
+ if len(message.AddedSubtasks) > 0 {
+ msg += "\n\n"
+ for _, subtask := range message.AddedSubtasks {
+ msg += "\nβ€’ " + subtask.Title
+ }
+ }
+
+ if message.Flags.IsImplementationStage && message.Subtask != nil {
+ msg += "\n\n" + "πŸ“‹ " + message.Subtask.Title
+ if len(message.Subtask.UsesFiles) > 0 {
+ for _, file := range message.Subtask.UsesFiles {
+ msg += "\n β€’ πŸ“„ " + file
+ }
+ }
+ }
+
+ if message.Flags.DidCompletePlan {
+ msg += "\n\n" + "🏁 Completed Plan"
+ }
+
// Cleaner without the cut off message - maybe need a separate command to show both the log and full messages?
// cutoff := 140
// if len(message.Message) > cutoff {
diff --git a/app/server/db/data_models.go b/app/server/db/data_models.go
index 7d320499..677531d7 100644
--- a/app/server/db/data_models.go
+++ b/app/server/db/data_models.go
@@ -448,30 +448,38 @@ func (context *Context) ToApi() *shared.Context {
}
type ConvoMessage struct {
- Id string `json:"id"`
- OrgId string `json:"orgId"`
- PlanId string `json:"planId"`
- UserId string `json:"userId"`
- Role string `json:"role"`
- Tokens int `json:"tokens"`
- Num int `json:"num"`
- Message string `json:"message"`
- Stopped bool `json:"stopped"`
- ReplyType shared.ReplyType `json:"replyType"`
- CreatedAt time.Time `json:"createdAt"`
+ Id string `json:"id"`
+ OrgId string `json:"orgId"`
+ PlanId string `json:"planId"`
+ UserId string `json:"userId"`
+ Role string `json:"role"`
+ Tokens int `json:"tokens"`
+ Num int `json:"num"`
+ Message string `json:"message"`
+ Stopped bool `json:"stopped"`
+ Subtask *Subtask `json:"subtask,omitempty"`
+ AddedSubtasks []*Subtask `json:"addedSubtasks,omitempty"`
+ Flags shared.ConvoMessageFlags `json:"flags"`
+ CreatedAt time.Time `json:"createdAt"`
}
func (msg *ConvoMessage) ToApi() *shared.ConvoMessage {
+ addedSubtasks := make([]*shared.Subtask, len(msg.AddedSubtasks))
+ for i, subtask := range msg.AddedSubtasks {
+ addedSubtasks[i] = subtask.ToApi()
+ }
return &shared.ConvoMessage{
- Id: msg.Id,
- UserId: msg.UserId,
- Role: msg.Role,
- Tokens: msg.Tokens,
- Num: msg.Num,
- Message: msg.Message,
- Stopped: msg.Stopped,
- ReplyType: msg.ReplyType,
- CreatedAt: msg.CreatedAt,
+ Id: msg.Id,
+ UserId: msg.UserId,
+ Role: msg.Role,
+ Tokens: msg.Tokens,
+ Num: msg.Num,
+ Message: msg.Message,
+ Stopped: msg.Stopped,
+ Flags: msg.Flags,
+ Subtask: msg.Subtask.ToApi(),
+ AddedSubtasks: addedSubtasks,
+ CreatedAt: msg.CreatedAt,
}
}
@@ -562,3 +570,15 @@ type Subtask struct {
UsesFiles []string `json:"usesFiles"`
IsFinished bool `json:"isFinished"`
}
+
+func (subtask *Subtask) ToApi() *shared.Subtask {
+ if subtask == nil {
+ return nil
+ }
+ return &shared.Subtask{
+ Title: subtask.Title,
+ Description: subtask.Description,
+ UsesFiles: subtask.UsesFiles,
+ IsFinished: subtask.IsFinished,
+ }
+}
diff --git a/app/server/db/result_helpers.go b/app/server/db/result_helpers.go
index 31caf8cd..d302f7b3 100644
--- a/app/server/db/result_helpers.go
+++ b/app/server/db/result_helpers.go
@@ -572,6 +572,7 @@ func ApplyPlan(ctx context.Context, orgId, userId, branchName string, plan *Plan
numRoutines := len(pendingDbResults) +
len(convoMessageDescriptions)
+
if len(pendingNewFilesSet) > 0 {
numRoutines++
}
@@ -588,6 +589,16 @@ func ApplyPlan(ctx context.Context, orgId, userId, branchName string, plan *Plan
msg := "βœ… Marked pending results as applied"
+ currentFiles := currentPlanState.CurrentPlanFiles.Files
+ var sortedFiles []string
+ for path := range currentFiles {
+ sortedFiles = append(sortedFiles, path)
+ }
+ sort.Strings(sortedFiles)
+ for _, path := range sortedFiles {
+ msg += fmt.Sprintf("\n β€’ πŸ“„ %s", path)
+ }
+
if loadContextRes != nil && !loadContextRes.MaxTokensExceeded {
msg += "\n\n" + loadContextRes.Msg
}
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index 75fb1427..9c69baae 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -160,28 +160,72 @@ func execTellPlan(params execTellPlanParams) {
}
log.Println("execTellPlan - Tell plan loaded")
+ log.Printf(`
+ iteration: %d
+ req.AutoContext: %t,
+ req.IsChatOnly: %t,
+ req.ExecEnabled: %t,
+ req.BuildMode: %s,
+ req.IsUserContinue: %t,
+ req.IsUserDebug: %t,
+ req.IsApplyDebug: %t,
+ shouldLoadFollowUpContext: %t,
+ didLoadFollowUpContext: %t,
+ didMakeFollowUpPlan: %t,
+ didLoadChatOnlyContext: %t,
+ state.hasContextMap: %t,
+ state.hasAssistantReply: %t,
+ len(state.subtasks): %d,
+ `,
+ iteration,
+ req.AutoContext,
+ req.IsChatOnly,
+ req.ExecEnabled,
+ req.BuildMode,
+ req.IsUserContinue,
+ req.IsUserDebug,
+ req.IsApplyDebug,
+ shouldLoadFollowUpContext,
+ didLoadFollowUpContext,
+ didMakeFollowUpPlan,
+ params.didLoadChatOnlyContext,
+ state.hasContextMap,
+ state.hasAssistantReply,
+ len(state.subtasks),
+ )
+
+ var lastConvoMsg *db.ConvoMessage
+ if len(state.convo) > 0 {
+ lastConvoMsg = state.convo[len(state.convo)-1]
+ }
+
+ wasContextStage := lastConvoMsg != nil && lastConvoMsg.Flags.IsContextStage
+ didMakePlan := lastConvoMsg != nil && lastConvoMsg.Flags.DidMakePlan
+ wasImplementationStage := lastConvoMsg != nil && lastConvoMsg.Flags.IsImplementationStage
+
+ isTrueUserContinue := iteration == 0 && req.IsUserContinue && lastConvoMsg != nil && lastConvoMsg.Role == openai.ChatMessageRoleAssistant
+ isUserPrompt := iteration == 0 && !isTrueUserContinue
+
+ hasSubtasks := len(state.subtasks) > 0
+
autoContextEnabled := req.AutoContext && state.hasContextMap
smartContextEnabled := req.AutoContext
- isFollowUp := shouldLoadFollowUpContext || (iteration == 0 && (len(state.subtasks) > 0 || (req.IsChatOnly && state.hasAssistantReply)))
+ isFollowUp := iteration == 0 && !isTrueUserContinue && (hasSubtasks || (req.IsChatOnly && state.hasAssistantReply))
isPlanningStage := req.IsChatOnly ||
- shouldLoadFollowUpContext ||
- didLoadFollowUpContext ||
- (!req.IsUserContinue &&
- !didMakeFollowUpPlan &&
- (iteration == 0 ||
- (autoContextEnabled && iteration == 1)))
+ lastConvoMsg == nil ||
+ isUserPrompt ||
+ (!didMakePlan && !wasImplementationStage)
- isImplementationStage := !isPlanningStage
+ isImplementationStage := !req.IsChatOnly && !isPlanningStage
- isContextStage := isPlanningStage &&
- (shouldLoadFollowUpContext ||
- (!isFollowUp && autoContextEnabled && !state.contextMapEmpty && iteration == 0))
+ isContextStage := autoContextEnabled && isPlanningStage && !isFollowUp && !state.contextMapEmpty && (isUserPrompt || !wasContextStage)
log.Printf("isPlanningStage: %t, isImplementationStage: %t, isContextStage: %t, isFollowUp: %t\n", isPlanningStage, isImplementationStage, isContextStage, isFollowUp)
state.isFollowUp = isFollowUp
+ state.willLoadFollowUpContext = shouldLoadFollowUpContext
state.isPlanningStage = isPlanningStage
state.isImplementationStage = isImplementationStage
state.isContextStage = isContextStage
diff --git a/app/server/model/plan/tell_stream_error.go b/app/server/model/plan/tell_stream_error.go
index 3cd9c76d..09839a53 100644
--- a/app/server/model/plan/tell_stream_error.go
+++ b/app/server/model/plan/tell_stream_error.go
@@ -116,7 +116,12 @@ func (state *activeTellStreamState) onError(params onErrorParams) onErrorResult
storedDesc := false
if convoMessageId == "" {
- assistantMsg, msg, err := state.storeAssistantReply("")
+ assistantMsg, msg, err := state.storeAssistantReply(shared.ConvoMessageFlags{
+ IsFollowUpReply: state.isFollowUp,
+ IsPlanningStage: state.isPlanningStage,
+ IsContextStage: state.isContextStage,
+ IsImplementationStage: state.isImplementationStage,
+ }, nil, nil)
if err == nil {
convoMessageId = assistantMsg.Id
commitMsg = msg
diff --git a/app/server/model/plan/tell_stream_finish.go b/app/server/model/plan/tell_stream_finish.go
index 72b74325..086e8921 100644
--- a/app/server/model/plan/tell_stream_finish.go
+++ b/app/server/model/plan/tell_stream_finish.go
@@ -69,7 +69,8 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedR
}
autoLoadContextFiles := state.checkAutoLoadContext()
- hasNewSubtasks := state.checkNewSubtasks()
+ addedSubtasks := state.checkNewSubtasks()
+ hasNewSubtasks := len(addedSubtasks) > 0
followUpNeedsContextStage := state.followUpNeedsContextStage()
handleDescAndExecStatusRes := state.handleDescAndExecStatus(autoLoadContextFiles, hasNewSubtasks)
@@ -87,12 +88,15 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedR
hasNewSubtasks: hasNewSubtasks,
followUpNeedsContextStage: followUpNeedsContextStage,
autoLoadContextFiles: autoLoadContextFiles,
+ addedSubtasks: addedSubtasks,
})
if storeOnFinishedResult.shouldContinueMainLoop || storeOnFinishedResult.shouldReturn {
return storeOnFinishedResult.handleStreamFinishedResult
}
allSubtasksFinished := storeOnFinishedResult.allSubtasksFinished
+ didLoadFollowUpContext := state.willLoadFollowUpContext && len(autoLoadContextFiles) > 0
+
// summarize convo needs to come *after* the reply is stored in order to correctly summarize the latest message
log.Println("summarize convo")
// summarize in the background
@@ -166,7 +170,6 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedR
if followUpNeedsContextStage {
log.Println("Clearing context before follow up context stage")
-
}
// if we're auto-loading context files, we always want to continue for at least another iteration with the loaded context
@@ -196,6 +199,7 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedR
shouldLoadFollowUpContext: followUpNeedsContextStage,
didMakeFollowUpPlan: state.isFollowUp && !followUpNeedsContextStage && hasNewSubtasks,
didLoadChatOnlyContext: len(autoLoadContextFiles) > 0 && req.IsChatOnly,
+ didLoadFollowUpContext: didLoadFollowUpContext,
})
} else {
var buildFinished bool
@@ -367,6 +371,7 @@ type storeOnFinishedParams struct {
hasNewSubtasks bool
followUpNeedsContextStage bool
autoLoadContextFiles []string
+ addedSubtasks []*db.Subtask
}
type storeOnFinishedResult struct {
@@ -388,6 +393,7 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParams
auth := state.auth
summarizedToMessageId := state.summarizedToMessageId
active := state.activePlan
+ addedSubtasks := params.addedSubtasks
var allSubtasksFinished bool
@@ -446,20 +452,42 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParams
}
}()
- var replyType shared.ReplyType
+ var flags shared.ConvoMessageFlags
+ if state.isFollowUp {
+ flags.IsFollowUpReply = true
+ }
+ if state.isPlanningStage {
+ flags.IsPlanningStage = true
+ }
+ if state.isContextStage {
+ flags.IsContextStage = true
+ }
+ if state.isImplementationStage {
+ flags.IsImplementationStage = true
+ }
if len(replyOperations) > 0 {
- replyType = shared.ReplyTypeImplementation
- } else if hasNewSubtasks {
- replyType = shared.ReplyTypeMadePlan
- } else if len(autoLoadContextFiles) > 0 {
- replyType = shared.ReplyTypeLoadedContext
- } else if followUpNeedsContextStage {
- replyType = shared.ReplyTypeContextAssessment
- } else {
- replyType = shared.ReplyTypeChat
+ flags.DidWriteCode = true
+ }
+ if hasNewSubtasks {
+ flags.DidMakePlan = true
+ }
+ if len(autoLoadContextFiles) > 0 {
+ flags.DidLoadContext = true
+ }
+ if state.isFollowUp {
+ flags.IsFollowUpReply = true
+ }
+ if subtaskFinished && state.currentSubtask != nil {
+ flags.DidCompleteTask = true
+ }
+ if allSubtasksFinished {
+ flags.DidCompletePlan = true
+ }
+ if hasNewSubtasks && state.req.IsApplyDebug || state.req.IsUserDebug {
+ flags.DidMakeDebuggingPlan = true
}
- assistantMsg, convoCommitMsg, err := state.storeAssistantReply(replyType) // updates state.convo
+ assistantMsg, convoCommitMsg, err := state.storeAssistantReply(flags, state.currentSubtask, addedSubtasks) // updates state.convo
if err != nil {
state.onError(onErrorParams{
@@ -590,7 +618,7 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParams
}
}
-func (state *activeTellStreamState) storeAssistantReply(replyType shared.ReplyType) (*db.ConvoMessage, string, error) {
+func (state *activeTellStreamState) storeAssistantReply(flags shared.ConvoMessageFlags, subtask *db.Subtask, addedSubtasks []*db.Subtask) (*db.ConvoMessage, string, error) {
currentOrgId := state.currentOrgId
currentUserId := state.currentUserId
planId := state.plan.Id
@@ -606,16 +634,20 @@ func (state *activeTellStreamState) storeAssistantReply(replyType shared.ReplyTy
activePlan := state.activePlan
+ // fmt.Println("raw message: ", activePlan.CurrentReplyContent)
+
assistantMsg := db.ConvoMessage{
- Id: replyId,
- OrgId: currentOrgId,
- PlanId: planId,
- UserId: currentUserId,
- Role: openai.ChatMessageRoleAssistant,
- Tokens: replyNumTokens,
- Num: num,
- Message: activePlan.CurrentReplyContent,
- ReplyType: replyType,
+ Id: replyId,
+ OrgId: currentOrgId,
+ PlanId: planId,
+ UserId: currentUserId,
+ Role: openai.ChatMessageRoleAssistant,
+ Tokens: replyNumTokens,
+ Num: num,
+ Message: activePlan.CurrentReplyContent,
+ Flags: flags,
+ Subtask: subtask,
+ AddedSubtasks: addedSubtasks,
}
commitMsg, err := db.StoreConvoMessage(&assistantMsg, auth.User.Id, branch, false)
@@ -644,5 +676,6 @@ func (state *activeTellStreamState) followUpNeedsContextStage() bool {
active := state.activePlan
return strings.Contains(active.CurrentReplyContent, "clear all context") ||
- strings.Contains(active.CurrentReplyContent, "decide what context I need")
+ strings.Contains(active.CurrentReplyContent, "decide what context") ||
+ strings.Contains(active.CurrentReplyContent, "need more context")
}
diff --git a/app/shared/convo_message.go b/app/shared/convo_message.go
new file mode 100644
index 00000000..6bc093c7
--- /dev/null
+++ b/app/shared/convo_message.go
@@ -0,0 +1,26 @@
+package shared
+
+func (f *ConvoMessageFlags) GetReplyTags() []string {
+ var replyTags []string
+ if f.DidLoadContext {
+ replyTags = append(replyTags, "πŸ“₯ Loaded Context")
+ }
+ if f.DidMakePlan {
+ if f.DidMakeDebuggingPlan {
+ replyTags = append(replyTags, "🐞 Made Debug Plan")
+ } else {
+ replyTags = append(replyTags, "πŸ“‹ Made Plan")
+ }
+ }
+ if f.DidWriteCode {
+ replyTags = append(replyTags, "πŸ‘¨β€πŸ’» Wrote Code")
+ }
+ // if f.DidCompleteTask {
+ // replyTags = append(replyTags, "βœ…")
+ // }
+ if f.DidCompletePlan {
+ replyTags = append(replyTags, "🏁")
+ }
+
+ return replyTags
+}
diff --git a/app/shared/data_models.go b/app/shared/data_models.go
index 611b844e..e19ba49d 100644
--- a/app/shared/data_models.go
+++ b/app/shared/data_models.go
@@ -114,26 +114,40 @@ type Context struct {
UpdatedAt time.Time `json:"updatedAt"`
}
-type ReplyType string
+type ConvoMessageFlags struct {
+ DidMakePlan bool `json:"didMakePlan"`
+ DidMakeDebuggingPlan bool `json:"didMakeDebuggingPlan"`
+ DidLoadContext bool `json:"didLoadContext"`
+ IsPlanningStage bool `json:"isPlanningStage"`
+ IsContextStage bool `json:"isContextStage"`
+ IsImplementationStage bool `json:"isImplementationStage"`
+ IsFollowUpReply bool `json:"isFollowUpReply"`
+ IsChat bool `json:"isChat"`
+ NeedsFollowUpContext bool `json:"needsFollowUpContext"`
+ DidWriteCode bool `json:"didWriteCode"`
+ DidCompleteTask bool `json:"didCompleteTask"`
+ DidCompletePlan bool `json:"didCompletePlan"`
+}
-const (
- ReplyTypeContextAssessment ReplyType = "context-assessment"
- ReplyTypeMadePlan ReplyType = "made-plan"
- ReplyTypeLoadedContext ReplyType = "loaded-context"
- ReplyTypeChat ReplyType = "chat"
- ReplyTypeImplementation ReplyType = "implementation"
-)
+type Subtask struct {
+ Title string `json:"title"`
+ Description string `json:"description"`
+ UsesFiles []string `json:"usesFiles"`
+ IsFinished bool `json:"isFinished"`
+}
type ConvoMessage struct {
- Id string `json:"id"`
- UserId string `json:"userId"`
- Role string `json:"role"`
- Tokens int `json:"tokens"`
- Num int `json:"num"`
- Message string `json:"message"`
- Stopped bool `json:"stopped"`
- ReplyType ReplyType `json:"replyType"`
- CreatedAt time.Time `json:"createdAt"`
+ Id string `json:"id"`
+ UserId string `json:"userId"`
+ Role string `json:"role"`
+ Tokens int `json:"tokens"`
+ Num int `json:"num"`
+ Message string `json:"message"`
+ Stopped bool `json:"stopped"`
+ Flags ConvoMessageFlags `json:"flags"`
+ Subtask *Subtask `json:"subtask,omitempty"`
+ AddedSubtasks []*Subtask `json:"addedSubtasks,omitempty"`
+ CreatedAt time.Time `json:"createdAt"`
}
type ConvoSummary struct {
diff --git a/app/shared/plan_result_pending_summary.go b/app/shared/plan_result_pending_summary.go
index 46ecab01..1eccf060 100644
--- a/app/shared/plan_result_pending_summary.go
+++ b/app/shared/plan_result_pending_summary.go
@@ -122,6 +122,16 @@ func (state *CurrentPlanState) pendingChangesSummary(forApply bool, commitSummar
}
msgs = append(msgs, "πŸ—οΈ Build pending changes")
+ currentFiles := state.CurrentPlanFiles.Files
+ var sortedFiles []string
+ for path := range currentFiles {
+ sortedFiles = append(sortedFiles, path)
+ }
+ sort.Strings(sortedFiles)
+ for _, path := range sortedFiles {
+ msgs = append(msgs, fmt.Sprintf(" β€’ πŸ“„ %s", path))
+ }
+ return strings.Join(msgs, "\n")
}
for _, ch := range sortedChangesets {