Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
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.goindex 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 weekformattedTs := 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.goindex 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.goindex 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.goindex 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 *PlannumRoutines := len(pendingDbResults) +len(convoMessageDescriptions)+if len(pendingNewFilesSet) > 0 {numRoutines++}@@ -588,6 +589,16 @@ func ApplyPlan(ctx context.Context, orgId, userId, branchName string, plan *Planmsg := "β 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.goindex 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.hasContextMapsmartContextEnabled := 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 = shouldLoadFollowUpContextstate.isPlanningStage = isPlanningStagestate.isImplementationStage = isImplementationStagestate.isContextStage = isContextStagediff --git a/app/server/model/plan/tell_stream_error.go b/app/server/model/plan/tell_stream_error.goindex 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) onErrorResultstoredDesc := falseif 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.IdcommitMsg = msgdiff --git a/app/server/model/plan/tell_stream_finish.go b/app/server/model/plan/tell_stream_finish.goindex 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) > 0followUpNeedsContextStage := state.followUpNeedsContextStage()handleDescAndExecStatusRes := state.handleDescAndExecStatus(autoLoadContextFiles, hasNewSubtasks)@@ -87,12 +88,15 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedRhasNewSubtasks: 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 messagelog.Println("summarize convo")// summarize in the background@@ -166,7 +170,6 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedRif 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() handleStreamFinishedRshouldLoadFollowUpContext: 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 boolfollowUpNeedsContextStage boolautoLoadContextFiles []string+ addedSubtasks []*db.Subtask}type storeOnFinishedResult struct {@@ -388,6 +393,7 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParamsauth := state.authsummarizedToMessageId := state.summarizedToMessageIdactive := state.activePlan+ addedSubtasks := params.addedSubtasksvar 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.convoif 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.currentOrgIdcurrentUserId := state.currentUserIdplanId := state.plan.Id@@ -606,16 +634,20 @@ func (state *activeTellStreamState) storeAssistantReply(replyType shared.ReplyTyactivePlan := 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.activePlanreturn 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.gonew file mode 100644index 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.goindex 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.goindex 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 {