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
lots of work on auto context loading, structured edit fixes, prompting, filemaps, etc
Dane Schneider81093a0a63b6
diff --git a/app/cli/api/methods.go b/app/cli/api/methods.goindex ac4ac6b3..9f29b6ba 100644--- a/app/cli/api/methods.go+++ b/app/cli/api/methods.go@@ -2117,3 +2117,36 @@ func (a *Api) GetFileMap(req shared.GetFileMapRequest) (*shared.GetFileMapResponreturn &respBody, nil}++func (a *Api) AutoLoadContext(planId, branch string, req shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {+ serverUrl := fmt.Sprintf("%s/plans/%s/%s/auto_load_context", GetApiHost(), planId, branch)+ reqBytes, err := json.Marshal(req)+ if err != nil {+ return nil, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error marshalling request: %v", err)}+ }++ // use the slow client since we may be uploading relatively large files+ resp, err := authenticatedSlowClient.Post(serverUrl, "application/json", bytes.NewBuffer(reqBytes))+ if err != nil {+ return nil, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error sending request: %v", err)}+ }+ defer resp.Body.Close()++ if resp.StatusCode >= 400 {+ errorBody, _ := io.ReadAll(resp.Body)+ apiErr := HandleApiError(resp, errorBody)+ tokenRefreshed, apiErr := refreshTokenIfNeeded(apiErr)+ if tokenRefreshed {+ return a.LoadContext(planId, branch, req)+ }+ return nil, apiErr+ }++ var loadContextResponse shared.LoadContextResponse+ err = json.NewDecoder(resp.Body).Decode(&loadContextResponse)+ if err != nil {+ return nil, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error decoding response: %v", err)}+ }++ return &loadContextResponse, nil+}diff --git a/app/cli/cmd/chat.go b/app/cli/cmd/chat.goindex ed1c36e7..64dcf949 100644--- a/app/cli/cmd/chat.go+++ b/app/cli/cmd/chat.go@@ -25,6 +25,7 @@ func init() {chatCmd.Flags().StringVarP(&tellPromptFile, "file", "f", "", "File containing prompt")chatCmd.Flags().BoolVarP(&autoConfirm, "yes", "y", false, "Automatically confirm context updates")+ chatCmd.Flags().BoolVar(&tellAutoContext, "auto-context", false, "Load and manage context automatically")}func doChat(cmd *cobra.Command, args []string) {@@ -54,5 +55,8 @@ func doChat(cmd *cobra.Command, args []string) {CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {return lib.CheckOutdatedContextWithOutput(false, autoConfirm, maybeContexts)},- }, prompt, false, false, false, false, false, true)+ }, prompt, plan_exec.TellFlags{+ IsChatOnly: true,+ AutoContext: tellAutoContext,+ })}diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.goindex 97af1551..789b0e2c 100644--- a/app/cli/cmd/continue.go+++ b/app/cli/cmd/continue.go@@ -51,7 +51,12 @@ func doContinue(cmd *cobra.Command, args []string) {CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {return lib.CheckOutdatedContextWithOutput(false, autoConfirm || tellAutoApply, maybeContexts)},- }, "", tellBg, tellStop, tellNoBuild, true, false, false)+ }, "", plan_exec.TellFlags{+ TellBg: tellBg,+ TellStop: tellStop,+ TellNoBuild: tellNoBuild,+ IsUserContinue: true,+ })if tellAutoApply {lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, true, autoCommit, !autoCommit)diff --git a/app/cli/cmd/debug.go b/app/cli/cmd/debug.goindex 63690202..fa42548c 100644--- a/app/cli/cmd/debug.go+++ b/app/cli/cmd/debug.go@@ -125,7 +125,7 @@ func doDebug(cmd *cobra.Command, args []string) {CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {return lib.CheckOutdatedContextWithOutput(false, true, maybeContexts)},- }, prompt, false, false, false, false, true, false)+ }, prompt, plan_exec.TellFlags{IsUserDebug: true})lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, true, autoCommit, !autoCommit)}diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.goindex 8829a254..49d3cf04 100644--- a/app/cli/cmd/tell.go+++ b/app/cli/cmd/tell.go@@ -6,11 +6,18 @@ import ("io""os""os/exec"+ "plandex/api""plandex/auth""plandex/lib""plandex/plan_exec""plandex/term""strings"+ "time"++ "context"++ "os/signal"+ "syscall""github.com/plandex/plandex/shared""github.com/spf13/cobra"@@ -25,6 +32,7 @@ var tellBg boolvar tellStop boolvar tellNoBuild boolvar tellAutoApply bool+var tellAutoContext bool// tellCmd represents the prompt commandvar tellCmd = &cobra.Command{@@ -48,6 +56,7 @@ func init() {tellCmd.Flags().BoolVar(&tellAutoApply, "apply", false, "Automatically apply changes (and confirm context updates)")tellCmd.Flags().BoolVarP(&autoCommit, "commit", "c", false, "Commit changes to git when --apply/-a is passed")+ tellCmd.Flags().BoolVar(&tellAutoContext, "auto-context", false, "Load and manage context automatically")}func doTell(cmd *cobra.Command, args []string) {@@ -77,9 +86,16 @@ func doTell(cmd *cobra.Command, args []string) {CurrentBranch: lib.CurrentBranch,ApiKeys: apiKeys,CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {- return lib.CheckOutdatedContextWithOutput(false, autoConfirm || tellAutoApply, maybeContexts)+ return lib.CheckOutdatedContextWithOutput(false, autoConfirm || tellAutoApply || tellAutoContext, maybeContexts)},- }, prompt, tellBg, tellStop, tellNoBuild, false, false, false)+ }, prompt, plan_exec.TellFlags{+ TellBg: tellBg,+ TellStop: tellStop,+ TellNoBuild: tellNoBuild,+ AutoContext: tellAutoContext,+ })++ maybeShowDiffs()if tellAutoApply {lib.MustApplyPlan(lib.CurrentPlanId, lib.CurrentBranch, true, autoCommit, !autoCommit)@@ -202,4 +218,59 @@ func validateTellFlags() {if autoCommit && !tellAutoApply {term.OutputErrorAndExit("🚨 --commit/-c can only be used with --apply/-a")}++ if tellAutoContext && tellBg {+ term.OutputErrorAndExit("🚨 --auto-context/-c can't be used with --bg")+ }+ if tellAutoContext && tellStop {+ term.OutputErrorAndExit("🚨 --auto-context/-c can't be used with --stop/-s")+ }+}++func maybeShowDiffs() {+ diffs, err := api.Client.GetPlanDiffs(lib.CurrentPlanId, lib.CurrentBranch, plainTextOutput || showDiffUi)+ if err != nil {+ term.OutputErrorAndExit("Error getting plan diffs: %v", err)+ return+ }++ if len(diffs) > 0 {+ cmd := exec.Command(os.Args[0], "diffs", "--ui")++ // Create a context that's cancelled when the program exits+ ctx, cancel := context.WithCancel(context.Background())++ // Ensure cleanup on program exit+ go func() {+ // Wait for program exit signal+ c := make(chan os.Signal, 1)+ signal.Notify(c, os.Interrupt, syscall.SIGTERM)+ <-c++ // Cancel context and kill the process+ cancel()+ if cmd.Process != nil {+ cmd.Process.Kill()+ }+ }()++ go func() {+ if err := cmd.Start(); err != nil {+ fmt.Fprintf(os.Stderr, "Error starting diffs command: %v\n", err)+ return+ }++ // Wait in a separate goroutine+ go cmd.Wait()++ // Wait for either context cancellation or process completion+ <-ctx.Done()+ if cmd.Process != nil {+ cmd.Process.Kill()+ }+ }()++ // Give the UI a moment to start+ time.Sleep(100 * time.Millisecond)+ }}diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex 8b0bad0b..2568bc2c 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -542,6 +542,54 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {}}+func AutoLoadContextFiles(files []string) (string, error) {+ loadContextReqs := shared.LoadContextRequest{}+ errCh := make(chan error, len(files))+ var mu sync.Mutex++ for _, path := range files {+ go func(path string) {+ body, err := os.ReadFile(path)+ if err != nil {+ errCh <- fmt.Errorf("failed to read file %s: %v", path, err)+ return+ }++ mu.Lock()+ defer mu.Unlock()++ loadContextReqs = append(loadContextReqs, &shared.LoadContextParams{+ ContextType: shared.ContextFileType,+ FilePath: path,+ Name: path,+ Body: string(body),+ })++ errCh <- nil+ }(path)+ }++ for i := 0; i < len(files); i++ {+ err := <-errCh+ if err != nil {+ return "", fmt.Errorf("failed to load context: %v", err)+ }+ }++ res, apiErr := api.Client.AutoLoadContext(CurrentPlanId, CurrentBranch, loadContextReqs)++ if apiErr != nil {+ return "", fmt.Errorf("failed to load context: %v", apiErr.Msg)+ }++ if res.MaxTokensExceeded {+ overage := res.TotalTokens - res.MaxTokens+ return "", fmt.Errorf("update would add %d 🪙 and exceed token limit (%d) by %d 🪙", res.TokensAdded, res.MaxTokens, overage)+ }++ return res.Msg, nil+}+func printAlreadyLoadedMsg(alreadyLoadedByComposite map[string]*shared.Context) {fmt.Println()pronoun := "they're"diff --git a/app/cli/plan_exec/params.go b/app/cli/plan_exec/params.goindex fbe99c52..ea2bfd51 100644--- a/app/cli/plan_exec/params.go+++ b/app/cli/plan_exec/params.go@@ -8,3 +8,14 @@ type ExecParams struct {ApiKeys map[string]stringCheckOutdatedContext func(maybeContexts []*shared.Context) (bool, bool, error)}++type TellFlags struct {+ TellBg bool+ TellStop bool+ TellNoBuild bool+ IsUserContinue bool+ IsUserDebug bool+ IsChatOnly bool+ AutoContext bool+ ContinuedAfterAction bool+}diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.goindex 281a5f26..60de5a1a 100644--- a/app/cli/plan_exec/tell.go+++ b/app/cli/plan_exec/tell.go@@ -18,13 +18,16 @@ import (func TellPlan(params ExecParams,prompt string,- tellBg,- tellStop,- tellNoBuild,- isUserContinue,- isDebugCmd,- isChatOnly bool,+ flags TellFlags,) {+ tellBg := flags.TellBg+ tellStop := flags.TellStop+ tellNoBuild := flags.TellNoBuild+ isUserContinue := flags.IsUserContinue+ isDebugCmd := flags.IsUserDebug+ isChatOnly := flags.IsChatOnly+ autoContext := flags.AutoContext+done := make(chan struct{})outputPromptIfTell := func() {@@ -115,6 +118,7 @@ func TellPlan(IsUserContinue: isUserContinue,IsUserDebug: isDebugCmd,IsChatOnly: isChatOnly,+ AutoContext: autoContext,ApiKey: legacyApiKey, // deprecatedEndpoint: openAIBase, // deprecatedApiKeys: params.ApiKeys,@@ -173,6 +177,7 @@ func TellPlan(term.PrintCmds("", "tell", "convo", "summary")}close(done)+}()}diff --git a/app/cli/stream_tui/model.go b/app/cli/stream_tui/model.goindex 77015f10..07829eb6 100644--- a/app/cli/stream_tui/model.go+++ b/app/cli/stream_tui/model.go@@ -55,6 +55,7 @@ type streamUIModel struct {missingFilePath stringmissingFileSelectedIdx intpromptedMissingFile bool+ autoLoadedMissingFile boolmissingFileContent stringmissingFileTokens intdiff --git a/app/cli/stream_tui/run.go b/app/cli/stream_tui/run.goindex 72d29571..c5ecec61 100644--- a/app/cli/stream_tui/run.go+++ b/app/cli/stream_tui/run.go@@ -101,8 +101,10 @@ func Quit() {return}mu.Lock()- defer mu.Unlock()- ui.Quit()+ if ui != nil {+ ui.Quit()+ }+ mu.Unlock()wg.Wait() // Wait for the UI to fully terminate@@ -126,3 +128,17 @@ func Send(msg shared.StreamMessage) {// log.Printf("sending stream message to UI: %s\n", msg.Type)ui.Send(msg)}++func ToggleVisibility(hide bool) {+ if ui == nil {+ return+ }+ mu.Lock()+ defer mu.Unlock()++ if hide {+ ui.Send(tea.ExitAltScreen())+ } else {+ ui.Send(tea.EnterAltScreen())+ }+}diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.goindex 24d3cf0d..e5559d62 100644--- a/app/cli/stream_tui/update.go+++ b/app/cli/stream_tui/update.go@@ -60,11 +60,12 @@ func (m streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {case tea.KeyMsg:switch {- case bubbleKey.Matches(msg, m.keymap.quit):- m.background = true- return &m, tea.Quit+ // more intuitive for ctrl+c to stop than send to background+ // case bubbleKey.Matches(msg, m.keymap.quit):+ // m.background = true+ // return &m, tea.Quit- case bubbleKey.Matches(msg, m.keymap.stop):+ case bubbleKey.Matches(msg, m.keymap.stop) || bubbleKey.Matches(msg, m.keymap.quit):apiErr := api.Client.StopPlan(lib.CurrentPlanId, lib.CurrentBranch)if apiErr != nil {log.Println("stop plan api error:", apiErr)@@ -232,30 +233,6 @@ func (m *streamUIModel) scrollEnd() {}func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate bool) (tea.Model, tea.Cmd) {- checkMissingFileFn := func() {- if msg.MissingFilePath != "" {- m.promptingMissingFile = true- m.missingFilePath = msg.MissingFilePath-- bytes, err := os.ReadFile(m.missingFilePath)- if err != nil {- log.Println("failed to read file:", err)- m.err = fmt.Errorf("failed to read file: %w", err)- return- }- m.missingFileContent = string(bytes)-- numTokens, err := shared.GetNumTokens(m.missingFileContent)-- if err != nil {- log.Println("failed to get num tokens:", err)- m.err = fmt.Errorf("failed to get num tokens: %w", err)- return- }-- m.missingFileTokens = numTokens- }- }// log.Println("streamUI received message:", msg.Type)// log.Println(spew.Sdump(msg))@@ -292,28 +269,34 @@ func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate bo}m.updateReplyDisplay()- checkMissingFileFn()+ return m.checkMissingFile(msg)case shared.StreamMessagePromptMissingFile:- checkMissingFileFn()+ return m.checkMissingFile(msg)case shared.StreamMessageReply:+ // ignore empty reply messages+ if msg.ReplyChunk == "" {+ return m, nil+ }+if m.starting {m.starting = false}if m.processing {- log.Println("Message reply, setting processing to false")+ log.Println("Non-empty message reply, setting processing to false")m.processing = false- if m.promptedMissingFile {+ if m.promptedMissingFile || m.autoLoadedMissingFile {+ log.Println("Prompted missing file or auto loaded missing file, resetting (and skipping 👇 marker)")m.promptedMissingFile = false+ m.autoLoadedMissingFile = false} else {+ log.Println("Not prompted missing file or auto loaded missing file, adding 👇 marker")m.reply += "\n\n👇\n\n"}}- // log.Println("reply chunk:", msg.ReplyChunk)-m.reply += msg.ReplyChunkif !deferUIUpdate {@@ -365,6 +348,23 @@ func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate boreturn m, tea.Batch(cmds...)+ case shared.StreamMessageLoadContext:+ msg, err := lib.AutoLoadContextFiles(msg.LoadContextFiles)+ if err != nil {+ log.Println("failed to auto load context files:", err)+ m.err = err+ return m, tea.Quit+ }++ m.reply += "\n\n" + msg + "\n\n"+ m.updateReplyDisplay()++ cmds := []tea.Cmd{m.spinner.Tick}+ if m.building {+ cmds = append(cmds, m.buildSpinner.Tick)+ }+ return m, tea.Batch(cmds...)+case shared.StreamMessageError:m.apiErr = msg.Errorreturn m, tea.Quit@@ -485,3 +485,62 @@ func (m *streamUIModel) selectedMissingFileOpt() (tea.Model, tea.Cmd) {return m, m.spinner.Tick}++func (m *streamUIModel) checkMissingFile(msg *shared.StreamMessage) (tea.Model, tea.Cmd) {+ if msg.MissingFilePath != "" {+ if msg.MissingFileAutoContext {+ m.processing = true+ m.autoLoadedMissingFile = true++ return m, tea.Batch(+ m.spinner.Tick,+ func() tea.Msg {+ bytes, err := os.ReadFile(msg.MissingFilePath)+ if err != nil {+ log.Println("failed to read file:", err)+ m.err = fmt.Errorf("failed to read file: %w", err)+ return tea.Quit+ }+ content := string(bytes)++ apiErr := api.Client.RespondMissingFile(lib.CurrentPlanId, lib.CurrentBranch, shared.RespondMissingFileRequest{+ Choice: shared.RespondMissingFileChoiceLoad,+ FilePath: msg.MissingFilePath,+ Body: content,+ })++ if apiErr != nil {+ log.Println("missing file prompt api error:", apiErr)+ m.apiErr = apiErr+ return tea.Quit+ }++ return nil+ },+ )+ }++ m.promptingMissingFile = true+ m.missingFilePath = msg.MissingFilePath++ bytes, err := os.ReadFile(m.missingFilePath)+ if err != nil {+ log.Println("failed to read file:", err)+ m.err = fmt.Errorf("failed to read file: %w", err)+ return m, nil+ }+ m.missingFileContent = string(bytes)++ numTokens, err := shared.GetNumTokens(m.missingFileContent)++ if err != nil {+ log.Println("failed to get num tokens:", err)+ m.err = fmt.Errorf("failed to get num tokens: %w", err)+ return m, nil+ }++ m.missingFileTokens = numTokens+ }++ return m, nil+}diff --git a/app/cli/types/api.go b/app/cli/types/api.goindex 09816b55..7515ae36 100644--- a/app/cli/types/api.go+++ b/app/cli/types/api.go@@ -103,4 +103,5 @@ type ApiClient interface {GetCreditsTransactions(pageSize, pageNum int) (*shared.CreditsLogResponse, *shared.ApiError)GetFileMap(req shared.GetFileMapRequest) (*shared.GetFileMapResponse, *shared.ApiError)+ AutoLoadContext(planId, branch string, req shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError)}diff --git a/app/server/db/context_helpers.go b/app/server/db/context_helpers.goindex d2ecd739..acbe3fb0 100644--- a/app/server/db/context_helpers.go+++ b/app/server/db/context_helpers.go@@ -6,6 +6,7 @@ import ("encoding/hex""encoding/json""fmt"+ "log""os""path/filepath""plandex-server/syntax"@@ -276,7 +277,21 @@ func LoadContexts(ctx Ctx, params LoadContextsParams) (*shared.LoadContextResponmaxTokens := settings.GetPlannerEffectiveMaxTokens()mapContextsByFilePath := make(map[string]Context)+ existingContexts, err := GetPlanContexts(orgId, planId, false, false)+ if err != nil {+ return nil, nil, fmt.Errorf("error getting existing contexts: %v", err)+ }+ existingContextsByName := make(map[string]bool)+ for _, context := range existingContexts {+ existingContextsByName[context.Name] = true+ }+for _, context := range *req {+ if existingContextsByName[context.Name] {+ log.Println("Context already loaded:", context.Name)+ continue+ }+tempId := uuid.New().String()var numTokens intdiff --git a/app/server/handlers/context_helper.go b/app/server/handlers/context_helper.goindex 03b45f98..2a9c664f 100644--- a/app/server/handlers/context_helper.go+++ b/app/server/handlers/context_helper.go@@ -14,7 +14,14 @@ import ("github.com/sashabaranov/go-openai")-func loadContexts(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth, loadReq *shared.LoadContextRequest, plan *db.Plan, branchName string) (*shared.LoadContextResponse, []*db.Context) {+func loadContexts(+ w http.ResponseWriter,+ r *http.Request,+ auth *types.ServerAuth,+ loadReq *shared.LoadContextRequest,+ plan *db.Plan,+ branchName string,+) (*shared.LoadContextResponse, []*db.Context) {// check file count and size limitstotalFiles := 0for _, context := range *loadReq {diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.goindex e1c26d84..51f69192 100644--- a/app/server/handlers/plans_exec.go+++ b/app/server/handlers/plans_exec.go@@ -355,6 +355,95 @@ func RespondMissingFileHandler(w http.ResponseWriter, r *http.Request) {log.Println("Successfully processed request for RespondMissingFileHandler")}+func AutoLoadContextHandler(w http.ResponseWriter, r *http.Request) {+ log.Println("Received request for AutoLoadContextHandler", "ip:", host.Ip)++ vars := mux.Vars(r)+ planId := vars["planId"]+ branch := vars["branch"]+ log.Println("planId: ", planId)+ log.Println("branch: ", branch)++ isProxy := r.URL.Query().Get("proxy") == "true"++ active := modelPlan.GetActivePlan(planId, branch)+ if active == nil {+ if isProxy {+ log.Println("No active plan on proxied request")+ http.Error(w, "No active plan", http.StatusNotFound)+ return+ }++ proxyActivePlanMethod(w, r, planId, branch, "auto_load_context")+ return+ }++ auth := Authenticate(w, r, true)+ if auth == nil {+ return+ }++ plan := authorizePlan(w, planId, auth)+ if plan == nil {+ return+ }++ 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.LoadContextRequest+ 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+ }++ res, dbContexts := loadContexts(w, r, auth, &requestBody, plan, branch)++ if res == nil {+ return+ }++ modelPlan.UpdateActivePlan(planId, branch, func(activePlan *types.ActivePlan) {+ activePlan.Contexts = append(activePlan.Contexts, dbContexts...)+ for _, dbContext := range dbContexts {+ activePlan.ContextsByPath[dbContext.FilePath] = dbContext+ }+ })++ var apiContexts []*shared.Context+ for _, dbContext := range dbContexts {+ apiContexts = append(apiContexts, dbContext.ToApi())+ }++ msg := shared.SummaryForLoadContext(apiContexts, res.TokensAdded, res.TotalTokens)+ markdownRes := shared.LoadContextResponse{+ TokensAdded: res.TokensAdded,+ TotalTokens: res.TotalTokens,+ MaxTokensExceeded: res.MaxTokensExceeded,+ MaxTokens: res.MaxTokens,+ Msg: msg,+ }++ bytes, err := json.Marshal(markdownRes)+ if err != nil {+ log.Printf("Error marshalling response: %v\n", err)+ http.Error(w, "Error marshalling response", http.StatusInternalServerError)+ return+ }++ w.Write(bytes)++ active.AutoLoadContextCh <- struct{}{}++ log.Println("Successfully processed request for AutoLoadContextHandler")+}+func authorizePlanExecUpdate(w http.ResponseWriter, planId string, auth *types.ServerAuth) *db.Plan {plan := authorizePlan(w, planId, auth)if plan == nil {diff --git a/app/server/model/lib/context.go b/app/server/model/lib/context.goindex 3427a917..d50ccdeb 100644--- a/app/server/model/lib/context.go+++ b/app/server/model/lib/context.go@@ -8,7 +8,7 @@ import ("github.com/plandex/plandex/shared")-func FormatModelContext(context []*db.Context) (string, int, error) {+func FormatModelContext(context []*db.Context, includeMaps, includeTrees bool) (string, int, error) {var contextMessages []stringvar numTokens intfor _, part := range context {@@ -17,12 +17,18 @@ func FormatModelContext(context []*db.Context) (string, int, error) {var args []anyif part.ContextType == shared.ContextDirectoryTreeType {+ if !includeTrees {+ continue+ }fmtStr = "\n\n- %s | directory tree:\n\n```\n%s\n```"args = append(args, part.FilePath, part.Body)} else if part.ContextType == shared.ContextFileType {fmtStr = "\n\n- %s:\n\n```\n%s\n```"args = append(args, part.FilePath, part.Body)} else if part.ContextType == shared.ContextMapType {+ if !includeMaps {+ continue+ }fmtStr = "\n\n- %s | map:\n\n```\n%s\n```"args = append(args, part.FilePath, part.Body)} else if part.Url != "" {diff --git a/app/server/model/plan/activate.go b/app/server/model/plan/activate.goindex 2c23bcd9..5fff91ef 100644--- a/app/server/model/plan/activate.go+++ b/app/server/model/plan/activate.go@@ -11,7 +11,15 @@ import ("github.com/sashabaranov/go-openai")-func activatePlan(clients map[string]*openai.Client, plan *db.Plan, branch string, auth *types.ServerAuth, prompt string, buildOnly bool) (*types.ActivePlan, error) {+func activatePlan(+ clients map[string]*openai.Client,+ plan *db.Plan,+ branch string,+ auth *types.ServerAuth,+ prompt string,+ buildOnly,+ autoContext bool,+) (*types.ActivePlan, error) {active := GetActivePlan(plan.Id, branch)if active != nil {log.Printf("Tell: Active plan found for plan ID %s on branch %s\n", plan.Id, branch) // Log if an active plan is found@@ -29,7 +37,15 @@ func activatePlan(clients map[string]*openai.Client, plan *db.Plan, branch strinreturn nil, fmt.Errorf("plan %s branch %s already has an active stream on host %s", plan.Id, branch, modelStream.InternalIp)}- active = CreateActivePlan(auth.OrgId, auth.User.Id, plan.Id, branch, prompt, buildOnly)+ active = CreateActivePlan(+ auth.OrgId,+ auth.User.Id,+ plan.Id,+ branch,+ prompt,+ buildOnly,+ autoContext,+ )modelStream = &db.ModelStream{OrgId: auth.OrgId,diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.goindex 38b21e65..be9d30bf 100644--- a/app/server/model/plan/build_finish.go+++ b/app/server/model/plan/build_finish.go@@ -186,6 +186,7 @@ func (state *activeBuildStreamFileState) onFinishBuild() {if active != nil && (active.RepliesFinished || active.BuildOnly) {if state.tellState != nil {+ log.Println("Build is finished and replies are finished, calling verifyOrFinish")state.tellState.verifyOrFinish()} else {active.Finish()diff --git a/app/server/model/plan/build_load.go b/app/server/model/plan/build_load.goindex 1a08ba53..327d3840 100644--- a/app/server/model/plan/build_load.go+++ b/app/server/model/plan/build_load.go@@ -18,7 +18,7 @@ func (state *activeBuildStreamState) loadPendingBuilds() (map[string][]*types.Acbranch := state.branchauth := state.auth- active, err := activatePlan(clients, plan, branch, auth, "", true)+ active, err := activatePlan(clients, plan, branch, auth, "", true, false)if err != nil {log.Printf("Error activating plan: %v\n", err)diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.goindex 4cc12fc4..1394f736 100644--- a/app/server/model/plan/build_structured_edits.go+++ b/app/server/model/plan/build_structured_edits.go@@ -197,22 +197,66 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {}}- fileContentLines := strings.Split(activeBuild.FileContent, "\n")+ fileContent := activeBuild.FileContent+ fileContentLines := strings.Split(fileContent, "\n")var references []syntax.Referencevar removals []syntax.Removal+ var beginsWithRef bool = false+ var endsWithRef bool = false+ var foundNonRefLine bool = false+for i, line := range fileContentLines {line = strings.ToLower(strings.TrimSpace(line))+if strings.Contains(line, "... existing code ...") {references = append(references, syntax.Reference(i+1))- }- if strings.Contains(line, "plandex: removed code") {+ if !foundNonRefLine {+ beginsWithRef = true+ }+ endsWithRef = true+ } else if strings.Contains(line, "plandex: removed code") {removals = append(removals, syntax.Removal(i+1))+ } else if line != "" {+ foundNonRefLine = true+ endsWithRef = false+ }+ }++ if !beginsWithRef &&+ !strings.Contains(activeBuild.FileDescription, "overwrite the entire file") &&+ !strings.Contains(activeBuild.FileDescription, "the start of the file") {++ // structured edits handle normalization of comments, so just use // ... existing code ... here+ fileContentLines = append([]string{"// ... existing code ..."}, fileContentLines...)++ // bump all existing references up by 1+ for i, ref := range references {+ references[i] = syntax.Reference(int(ref) + 1)}+ references = append([]syntax.Reference{syntax.Reference(1)}, references...)+ }++ if !endsWithRef &&+ !strings.Contains(activeBuild.FileDescription, "overwrite the entire file") &&+ !strings.Contains(activeBuild.FileDescription, "the end of the file") {+ fileContentLines = append(fileContentLines, "// ... existing code ...")+ references = append(references, syntax.Reference(len(fileContentLines)))}- updatedFile, err := syntax.ApplyChanges(activePlan.Ctx, fileState.language, parser, originalFile, activeBuild.FileContent, references, removals, anchorLines)+ fileContent = strings.Join(fileContentLines, "\n")++ updatedFile, err := syntax.ApplyChanges(+ activePlan.Ctx,+ fileState.language,+ parser,+ originalFile,+ fileContent,+ references,+ removals,+ anchorLines,+ )if err != nil {log.Printf("buildStructuredEdits - error applying references: %v\n", err)fileState.structuredEditRetryOrError(fmt.Errorf("error applying references: %v", err))diff --git a/app/server/model/plan/state.go b/app/server/model/plan/state.goindex 1d7aa62b..f5b2e850 100644--- a/app/server/model/plan/state.go+++ b/app/server/model/plan/state.go@@ -19,8 +19,8 @@ func GetActivePlan(planId, branch string) *types.ActivePlan {return activePlans.Get(strings.Join([]string{planId, branch}, "|"))}-func CreateActivePlan(orgId, userId, planId, branch, prompt string, buildOnly bool) *types.ActivePlan {- activePlan := types.NewActivePlan(orgId, userId, planId, branch, prompt, buildOnly)+func CreateActivePlan(orgId, userId, planId, branch, prompt string, buildOnly, autoContext bool) *types.ActivePlan {+ activePlan := types.NewActivePlan(orgId, userId, planId, branch, prompt, buildOnly, autoContext)key := strings.Join([]string{planId, branch}, "|")activePlans.Set(key, activePlan)diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 0ba65015..88a578fd 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -21,7 +21,15 @@ import (func Tell(clients map[string]*openai.Client, plan *db.Plan, branch string, auth *types.ServerAuth, req *shared.TellPlanRequest) error {log.Printf("Tell: Called with plan ID %s on branch %s\n", plan.Id, branch)- _, err := activatePlan(clients, plan, branch, auth, req.Prompt, false)+ _, err := activatePlan(+ clients,+ plan,+ branch,+ auth,+ req.Prompt,+ false,+ req.AutoContext,+ )if err != nil {log.Printf("Error activating plan: %v\n", err)@@ -156,7 +164,17 @@ func execTellPlan(}}- modelContextText, modelContextTokens, err := lib.FormatModelContext(state.modelContext)+ // if auto context is enabled, we only include maps and trees on the first iteration, which is the context-gathering step+ var (+ includeMaps = true+ includeTrees = true+ )+ if req.AutoContext && iteration > 0 {+ includeMaps = false+ includeTrees = false+ }++ modelContextText, modelContextTokens, err := lib.FormatModelContext(state.modelContext, includeMaps, includeTrees)if err != nil {err = fmt.Errorf("error formatting model modelContext: %v", err)log.Println(err)@@ -169,7 +187,17 @@ func execTellPlan(return}- systemMessageText := prompts.SysCreate + modelContextText+ var sysCreate string+ if req.AutoContext {+ if iteration == 0 {+ sysCreate = prompts.AutoContextPreamble+ } else {+ sysCreate = prompts.SysCreateAutoContext+ }+ } else {+ sysCreate = prompts.SysCreateBasic+ }+ systemMessageText := sysCreate + modelContextTextsystemMessage := openai.ChatCompletionMessage{Role: openai.ChatMessageRoleSystem,Content: systemMessageText,@@ -246,10 +274,21 @@ func execTellPlan(promptTokens = prompts.PromptWrapperTokens + numPromptTokens}- state.tokensBeforeConvo = prompts.CreateSysMsgNumTokens + modelContextTokens + state.latestSummaryTokens + promptTokens+ var sysCreateTokens int+ if req.AutoContext {+ if iteration == 0 {+ sysCreateTokens = prompts.AutoContextPreambleNumTokens+ } else {+ sysCreateTokens = prompts.SysCreateAutoContextNumTokens+ }+ } else {+ sysCreateTokens = prompts.SysCreateBasicNumTokens+ }++ state.tokensBeforeConvo = sysCreateTokens + modelContextTokens + state.latestSummaryTokens + promptTokens// print out breakdown of token usage- log.Printf("System message tokens: %d\n", prompts.CreateSysMsgNumTokens)+ log.Printf("System message tokens: %d\n", sysCreateTokens)log.Printf("Context tokens: %d\n", modelContextTokens)log.Printf("Prompt tokens: %d\n", promptTokens)log.Printf("Latest summary tokens: %d\n", state.latestSummaryTokens)diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex fe98c863..e480c375 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -204,6 +204,9 @@ mainLoop:var generatedDescription *db.ConvoMessageDescriptionvar shouldContinue boolvar nextTask string++ autoLoadContextFiles := state.checkAutoLoadContext()+var errCh = make(chan error, 2)go func() {@@ -225,18 +228,32 @@ mainLoop:errCh <- nil}()- go func() {- log.Println("Getting exec status")- shouldContinue, nextTask, err = state.execStatusShouldContinue(active.CurrentReplyContent, latestSummaryCh, active.Ctx)- if err != nil {- errCh <- fmt.Errorf("failed to get exec status: %v", err)- return+ if req.IsChatOnly || len(autoLoadContextFiles) > 0 {+ // no auto continue for chat only+ if req.IsChatOnly {+ shouldContinue = false}- log.Printf("Should continue: %v\n", shouldContinue)+ // if we're auto-loading context files, we always want to continue for at least another iteration with the loaded context (even if it's chat only)+ if len(autoLoadContextFiles) > 0 {+ shouldContinue = true+ }errCh <- nil- }()+ } else {+ go func() {+ log.Println("Getting exec status")+ shouldContinue, nextTask, err = state.execStatusShouldContinue(active.CurrentReplyContent, latestSummaryCh, active.Ctx)+ if err != nil {+ errCh <- fmt.Errorf("failed to get exec status: %v", err)+ return+ }++ log.Printf("Should continue: %v\n", shouldContinue)++ errCh <- nil+ }()+ }for i := 0; i < 2; i++ {err := <-errCh@@ -387,7 +404,32 @@ mainLoop:ap.CurrentReplyDoneCh = nil})- if !req.IsChatOnly && req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations {+ if len(autoLoadContextFiles) > 0 {+ log.Println("Sending stream message to load context files")++ active.Stream(shared.StreamMessage{+ Type: shared.StreamMessageLoadContext,+ LoadContextFiles: autoLoadContextFiles,+ })+ active.FlushStreamBuffer()++ log.Println("Waiting for client to auto load context (30s timeout)")++ select {+ case <-active.Ctx.Done():+ log.Println("Context cancelled while waiting for auto load context")+ execHookOnStop(true)+ return+ case <-time.After(30 * time.Second):+ log.Println("Timeout waiting for auto load context")+ state.onError(fmt.Errorf("timeout waiting for auto load context response"), true, "", "")+ continue mainLoop+ case <-active.AutoLoadContextCh:+ }+ }++ // if we're auto-loading context files, we always want to continue for at least another iteration with the loaded context+ if len(autoLoadContextFiles) > 0 || (req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations) {log.Println("Auto continue plan")// continue planexecTellPlan(clients, plan, branch, auth, req, iteration+1, "", false, nextTask, "", 0)@@ -403,14 +445,14 @@ mainLoop:time.Sleep(50 * time.Millisecond)if buildFinished {- log.Println("Plan is finished")+ log.Println("Reply is finished and build is finished, calling verifyOrFinish")state.verifyOrFinish()} else {log.Println("Plan is still building")if active.ShouldVerifyDiff() {// If we're going to verify the diffs when build finishes, then replies aren't finished yet so we'll just continue here- log.Println("Replies aren't finished yet—waiting on verify diff step")+ log.Println("Build isn't finished yet—waiting on verify diff step")continue mainLoop} else {log.Println("Updating status to building")@@ -515,8 +557,9 @@ mainLoop:log.Printf("Prompting user for missing file: %s\n", currentFile)active.Stream(shared.StreamMessage{- Type: shared.StreamMessagePromptMissingFile,- MissingFilePath: currentFile,+ Type: shared.StreamMessagePromptMissingFile,+ MissingFilePath: currentFile,+ MissingFileAutoContext: active.AutoContext,})log.Printf("Stopping stream for missing file: %s\n", currentFile)@@ -535,6 +578,10 @@ mainLoop:log.Println("Context cancelled while waiting for missing file response")execHookOnStop(true)return+ case <-time.After(30 * time.Minute): // long timeout here since we're waiting for user input+ log.Println("Timeout waiting for missing file choice")+ state.onError(fmt.Errorf("timeout waiting for missing file choice"), true, "", "")+ continue mainLoopcase userChoice = <-active.MissingFileResponseCh:}@@ -672,6 +719,53 @@ func (state *activeTellStreamState) storeAssistantReply() (*db.ConvoMessage, strreturn &assistantMsg, commitMsg, err}+func (state *activeTellStreamState) checkAutoLoadContext() []string {+ activePlan := GetActivePlan(state.plan.Id, state.branch)++ if activePlan == nil {+ return nil+ }++ if !activePlan.AutoContext {+ return nil+ }++ // only load context on the first iteration+ if state.iteration > 0 {+ return nil+ }++ split := strings.Split(activePlan.CurrentReplyContent, "### Load Context")++ if len(split) < 2 {+ return nil+ }++ req := state.req++ list := strings.Split(split[1], "\n")+ files := []string{}++ for _, line := range list {+ trimmed := strings.TrimSpace(line)+ if trimmed == "" {+ continue+ }++ if strings.HasPrefix(trimmed, "-") {+ trimmed = strings.TrimPrefix(trimmed, "-")+ trimmed = strings.ReplaceAll(trimmed, "`", "")+ trimmed = strings.TrimSpace(trimmed)++ if req.ProjectPaths[trimmed] {+ files = append(files, trimmed)+ }+ }+ }++ return files+}+func (state *activeTellStreamState) onError(streamErr error, storeDesc bool, convoMessageId, commitMsg string) {log.Printf("\nStream error: %v\n", streamErr)diff --git a/app/server/model/plan/tell_verify.go b/app/server/model/plan/tell_verify.goindex 2bc57492..e258645e 100644--- a/app/server/model/plan/tell_verify.go+++ b/app/server/model/plan/tell_verify.go@@ -4,12 +4,15 @@ import ("log""net/http""plandex-server/db"+ "plandex-server/types""strings""github.com/plandex/plandex/shared")func (state *activeTellStreamState) verifyOrFinish() {+ log.Println("Verifying or finishing")+plan := state.planplanId := plan.Idbranch := state.branch@@ -23,7 +26,12 @@ func (state *activeTellStreamState) verifyOrFinish() {}if active.ShouldVerifyDiff() {+ log.Println("Should verify diff")+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {+ ap.IsVerifyingDiff = true+ })+ log.Println("Locking repo and getting diffs")repoLockId, err := db.LockRepo(db.LockRepoParams{OrgId: currentOrgId,@@ -47,6 +55,7 @@ func (state *activeTellStreamState) verifyOrFinish() {diffs, err := func() (string, error) {defer func() {+ log.Println("Unlocking repo after verify diff")err := db.DeleteRepoLock(repoLockId)if err != nil {log.Printf("Error unlocking repo after verify diff: %v\n", err)@@ -64,6 +73,9 @@ func (state *activeTellStreamState) verifyOrFinish() {if err != nil {log.Printf("Error getting plan diffs for verify diff: %v\n", err)+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {+ ap.IsVerifyingDiff = false+ })active.StreamDoneCh <- &shared.ApiError{Type: shared.ApiErrorTypeOther,Status: http.StatusInternalServerError,@@ -73,16 +85,29 @@ func (state *activeTellStreamState) verifyOrFinish() {}if len(strings.TrimSpace(diffs)) == 0 {+ log.Println("No diffs, finishing")+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {+ ap.IsVerifyingDiff = false+ })active.Finish()} else {+ log.Println("Got diffs, verifying")state.verifyDiffs(diffs)}} else {- active.Finish()+ log.Println("Not verifying, finishing unless another verification is already in progress")+ if !active.IsVerifyingDiff {+ log.Println("No verification in progress, finishing")+ active.Finish()+ } else {+ log.Println("Another verification is already in progress, skipping")+ }}}func (state *activeTellStreamState) verifyDiffs(diffs string) {+ log.Println("Verifying diffs")+plan := state.planplanId := plan.Idbranch := state.branch@@ -94,9 +119,15 @@ func (state *activeTellStreamState) verifyDiffs(diffs string) {}defer func() {- active.DidVerifyDiff = true+ log.Println("Setting DidVerifyDiff to true")+ UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {+ ap.DidVerifyDiff = true+ ap.IsVerifyingDiff = false+ })}()+ log.Println("Executing tell plan")+execTellPlan(state.clients,plan,diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.goindex 025ae080..fb6d0f10 100644--- a/app/server/model/prompts/create.go+++ b/app/server/model/prompts/create.go@@ -6,24 +6,149 @@ import ("github.com/plandex/plandex/shared")-const SysCreate = Identity + ` A plan is a set of files with an attached context.` ++func init() {+ var err error++ AutoContextPreambleNumTokens, err = shared.GetNumTokens(AutoContextPreamble)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for context preamble: %v", err))+ }++ SysCreateBasicNumTokens, err = shared.GetNumTokens(SysCreateBasic)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))+ }++ SysCreateAutoContextNumTokens, err = shared.GetNumTokens(SysCreateAutoContext)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))+ }++ PromptWrapperTokens, err = shared.GetNumTokens(fmt.Sprintf(promptWrapperFormatStr, ""))++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))+ }++ AutoContinuePromptTokens, err = shared.GetNumTokens(AutoContinuePrompt)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for auto continue prompt: %v", err))+ }++ VerifyDiffsPromptTokens, err = shared.GetNumTokens(VerifyDiffsPrompt)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for verify diffs prompt: %v", err))+ }++ DebugPromptTokens, err = shared.GetNumTokens(DebugPrompt)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for debug prompt: %v", err))+ }++ ChatOnlyPromptTokens, err = shared.GetNumTokens(ChatOnlyPrompt)++ if err != nil {+ panic(fmt.Sprintf("Error getting number of tokens for chat only prompt: %v", err))+ }+}++type CreatePromptParams struct {+ AutoContext bool+}++var SysCreateBasic = GetCreatePrompt(CreatePromptParams{+ AutoContext: false,+})+var SysCreateBasicNumTokens int- "[YOUR INSTRUCTIONS:]" ++var SysCreateAutoContext = GetCreatePrompt(CreatePromptParams{+ AutoContext: true,+})+var SysCreateAutoContextNumTokens int- `First, decide if the user has a task for you.+const AutoContextPreamble = Identity + ` A plan is a set of files with an attached context.- *If the user doesn't have a task and is just asking a question or chatting, or if 'chat mode' is enabled*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but don't include labelled code blocks as described below, since that indicates that a plan is being created. If a plan is in progress, follow the instructions below.+[YOUR INSTRUCTIONS:]++You are operating in 'auto-context mode'. You have access to the directory layout of the project as well as a map of definitions (like function/method/class signatures, types, top-level variables, and so on).++In response to the user's latest prompt, do the following:++ - Decide whether you've been given enough information to load necessary context and make a plan (if you've been given a task) or give a helpful response to the user (if you're responding in chat form). In general, do your best with whatever information you've been provided. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information. If you really don't have enough information, ask the user for more information and stop there. 'Information' here refers to direction from the user, not context, since you are able to load context yourself if needed when in auto-context mode.++ - Reply with an overview of how you will approach implementing the task (if you've been given a task) or responding to the user (if you're responding in chat form). Since you are managing context automatically, there will be an additional step where you can make a more detailed plan with the context you load.- *If the user does have a task*, create a plan for the task based on user-provided context using the following steps:+ - In your own words state something to the effect of: "Since I'm managing context automatically, I'll begin by examining the codebase and determining which files I need."++ - Using the directory layout and the map, explain how the project is organized, with particular focus on areas that may be relevant to the user's task, question, or message.++ - For each step in the plan, also note which files will be needed in context to complete the step. This MUST include *all* files that will be updated, but can also include other files that will be helpful, like examples of similar code, documentation, and so on. Be thorough and exhaustive in listing all files that are necessary or helpful to completing the plan effectively.++ - If you aren't sure whether a file will be helpful or not, but you think it might be, include it in the 'Load Context' list. It's better to load more context than you need than to miss an important or helpful file.++ - For each step in the plan, also note if the necessary files are *already* in context. If so, you MUST NOT load them again—they must be omitted from the 'Load Context' list.++ - At the end of your response, list *all* of those files (which are *not* already in context) in this format:++ ### Load Context+ - ` + "`src/main.rs`" + `+ - ` + "`lib/term.go`" + `++ Then immediately *stop there* so these files can be loaded before you continue. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "`src/main.rs`." + `++ - If instead you already have enough information from the directory layout, map, and current context to make a detailed plan or respond effectively to the user, then explicitly say "No context needs to be loaded." and continue on to the instructions below.++You ABSOLUTELY MUST do the above steps *BEFORE* continuing to the instructions below. Listing subtasks, responding to the user, or writing code in file blocks MUST come *after* you've done the above steps.+If your response included a 'Load Context' list as described above, you ABSOLUTELY MUST STOP after listing all those files. Do NOT continue to the instructions below and DO NOT output anything else after the 'Load Context' list—it must be the final text in your response.++The 'Load Context' list MUST *ONLY* include files that are present in the directory layout or map and are not *already* in context. You MUST NOT include any files that are already in context or that do not exist in the directory layout or map. Do NOT include files that will be created during the plan but are not yet present in the directory layout or map.++Don't output multiple lists of the files to load in your response. There should only be one 'Load Context' list in your response.++[END OF YOUR INSTRUCTIONS]+`++var AutoContextPreambleNumTokens int++func GetCreatePrompt(params CreatePromptParams) string {+ prompt := Identity + ` A plan is a set of files with an attached context.++ [YOUR INSTRUCTIONS:]++ First, decide if the user has a task for you.++ *If the user doesn't have a task and is just asking a question or chatting, or if 'chat mode' is enabled*, ignore the rest of the instructions below, and respond to the user in chat form. You can make reference to the context to inform your response, and you can include code in your response, but don't include labelled code blocks as described below, since that indicates that a plan is being created.++ *If the user does have a task or if you're continuing a plan that is already in progress*, and if 'chat mode' is *not* enabled, create a plan for the task based on user-provided context using the following steps:+ `++ if params.AutoContext {+ prompt += `+ 1. Decide whether you've been given enough information to make a plan.+ - Do your best with whatever information you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information.+ a. If you really don't have enough information to make a plan:+ - Explicitly say "I need more information to make a plan for this task."+ - Ask the user for more information and stop there.+ `+ } else {+ prompt += `1. Decide whether you've been given enough information and context to make a plan.- Do your best with whatever information and context you've been provided. Choose sensible values and defaults where appropriate. Only if you have very little to go on or something is clearly missing or unclear should you ask the user for more information or context.a. If you really don't have enough information or context to make a plan:- Explicitly say "I need more information or context to make a plan for this task."- Ask the user for more information or context and stop there.+ `+ }- 2. Decide whether this task is small enough to be completed in a single response.- a. If so, describe the task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:+ prompt += `2. Decide whether this task is small enough to be completed in a single response.+ a. If so, describe the task to be done and what your approach will be, then write out the code to complete the task. Include only lines that will change and lines that are necessary to know where the changes should be applied. Precede the code block with the file path like this '- file_path:'--for example:- src/main.rs:- lib/term.go:- main.py:@@ -31,7 +156,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context***You *must not* include **any other text** in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. Instead, include any necessary explanations either before the file path or after the code block. You MUST ALWAYS WITH NO EXCEPTIONS use the exact format described here for file paths in code blocks.***Do NOT include the file path again within the triple backticks, inside the code block itself. The file path must be included *only* in the file block label *preceding* the opening triple backticks.***- Labelled code block examples:+ Labelled code block example:- src/game.h:` + "```c" + `@@ -45,12 +170,22 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context` + "```" + `b. If not:- Explicitly say "Let's break up this task."- - Divide the task into smaller subtasks and list them in a numbered list. Subtasks MUST ALWAYS be numbered. Stop there.+ - Divide the task into smaller subtasks and list them in a numbered list. Subtasks MUST ALWAYS be numbered. Stop there.+ `++ if params.AutoContext {+ prompt += `+ - Since you are in 'auto-context mode', below the description of each subtask, you MUST include a comma-separated 'Uses:' list of the files that will be needed in context to complete each task. Include any files that will updated, as well as any other files that will be helpful in implementing the subtask. ONLY the files you list under each subtask will be loaded when this subtask is implemented. List files individually—do not list directories. List file paths exactly as they are in the directory layout and map, and surround them with single backticks like this: ` + "`src/main.rs`." + `+ `+ }++ prompt += `- If you are already working on a subtask and the subtask is still too large to be implemented in a single response, it should be further broken down into smaller subtasks. In that case, explicitly say "Let's further break up this subtask", further divide the subtask into even smaller steps, and list them in a numbered list. Stop there. Do NOT do this repetitively for the same subtask. Only break down a given subtask into smaller steps once.- Be thorough and exhaustive in your list of subtasks. Ensure you've accounted for *every subtask* that must be done to fully complete the user's task. Ensure that you list *every* file that needs to be created or updated. Be specific and detailed in your list of subtasks.- Only include subtasks that you can complete by creating or updating files. If a subtask requires executing code or commands, mention it to the user, but do not include it as a subtask in the plan. Do not include subtasks like "Testing and integration" or "Deployment" that require executing code or commands. Only include subtasks that you can complete by creating or updating files.- Only break the task up into subtasks that you can do yourself. If a subtask requires executing code or commands, or other tasks that go beyond coding like testing or verifying, deploying, user testing, and son, you can mention it to the user, but you MUST NOT include it as a subtask in the plan. Only include subtasks that can be completed directly with code by creating or updating files.- Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.+ - Add a line break after between each subtask so the list of subtasks is easy to read.- Do NOT ask the user to confirm after you've made subtasks. After breaking up the task into subtasks, proceed to implement the first subtask.## Code blocks and files@@ -75,17 +210,15 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextIf a change is related to code in an existing file in context, make the change as an update to the existing file. Do NOT create a new file for a change that applies to an existing file in context. For example, if there is an 'Page.tsx' file in the existing context and the user has asked you to update the structure of the page component, make the change in the existing 'Page.tsx' file. Do NOT create a new file like 'page.tsx' or 'NewPage.tsx' for the change. If the user has specifically asked you to apply a change to a new file, then you can create a new file. If there is no existing file that makes sense to apply a change to, then you can create a new file.+ ` + ChangeExplanationPrompt + `+For code in markdown blocks, always include the language name after the opening triple backticks.If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.- An exception to the above instructions on comments are if a file block is empty because you removed everything in it. In that case, leave a brief one-line comment starting with 'Removed' that describes unambiguously what was removed so that the file block isn't empty.-- When you are updating an existing file in context: include the *minimum amount of code* necessary in code blocks to describe the suggested changes. Include only lines that are changing and lines that make it clear where the change should be applied. When updating an existing file in context, you can use the *reference comment* "// ... existing code ..." (with the appropriate comment symbol for the programming language) instead of including large sections from the original file in order to make it clear where changes should be applied. You *must not* include more lines from the original file than are absolutely necessary to make the location, structure, and order of suggested changes clear.-- Instead, show only the code that is changing and the immediately surrounding code that is necessary to understand the changes. Use the comment "// ... existing code ..." (with the appropriate comment symbol for the programming language) to replace sections of code from the original file and denote where the existing code should be placed. Again, this only applies when you are updating an existing file in context. It does not apply when you are creating a new file. You MUST NOT use the comment "// ... existing code ..." (or any equivalent) when creating a new file.+ When updating an existing file in context, use the *reference comment* "// ... existing code ..." (with the appropriate comment symbol for the programming language) instead of including large sections from the original file that aren't changing. Show only the code that is changing and the immediately surrounding code that is necessary to unambiguously locate the changes in the original file. This only applies when you are *updating* an *existing file* in context. It does *not* apply when you are creating a new file. You MUST NEVER use the comment "// ... existing code ..." (or any equivalent) when creating a new file.` + UpdateFormatPrompt + `@@ -219,7 +352,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextIf the latest state of the context makes the current plan you are working on redundant, say so, mark the plan as complete, and stop there. Otherwise, implement the subtask.- Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you should always work from the *latest version* of the context when continuing the plan.+ Always work from the LATEST state of the user-provided context. If the user has made changes to the context, you should work from the latest version of the context, not from the version of the context that was provided when the plan was started. Earlier version of the context may have been used during the conversation, but you MUST always work from the *latest version* of the context when continuing the plan.## Responding to user questions@@ -228,7 +361,8 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context[END OF YOUR INSTRUCTIONS]`-var CreateSysMsgNumTokens int+ return prompt+}const promptWrapperFormatStr = "# The user's latest prompt:\n```\n%s\n```\n\n" + `Please respond according to the 'Your instructions' section above.@@ -240,6 +374,8 @@ Always use triple backticks to start and end code blocks.` + UpdateFormatPrompt + `+` + ChangeExplanationPrompt + `+Only list out subtasks once for the plan--after that, do not list or describe a subtask that can be implemented in code without including a code block that implements the subtask.Do not ask the user to do anything that you can do yourself with a code block. Do not say a task is too large or complex for you to complete--do your best to break down the task and complete it even if it's very large or complex.@@ -286,11 +422,15 @@ const SkippedPathsPrompt = "\n\nSome files have been skipped by the user and *mu// - If the plan is in progress, this is not your *first* response in the plan, the user's task or tasks have already been broken down into subtasks if necessary, and the plan is *not yet complete* and should be continued, you MUST ALWAYS start the response with "Now I'll" and then proceed to describe and implement the next step in the plan.-const VerifyDiffsPrompt = `Below are the diffs for the plan you've created. Based on the diffs, evaluate whether the plan has been completed correctly or whether there are problems to address. Pay particular attention to syntax errors, code that has been incorrectly removed, or code that has been incorrectlyduplicated.+const VerifyDiffsPrompt = `Below are the diffs for the plan you've created. Based on the diffs, evaluate whether the plan has been completed correctly or whether there are problems to address. Pay particular attention to syntax errors, code that has been incorrectly removed, or code that has been incorrectly duplicated.++Do NOT consider minor issues like whitespace, formatting, or ordering of code to be problems unless they are syntax errors or will cause the code to fail to run correctly.++You MUST NOT add additional features or functionality to the plan. Your job at this stage is to check your work and ensure that the diffs have been generated correctly based on the existing plan, not to increase the scope of the plan or add new tasks beyond fixing any problems in the diffs. Focus on objective, serious problems that will prevent the code from running correctly, not minor issues or subjective improvements that aren't necessary for the code to run correctly.-You MUST NOT add additional features or functionality to the plan. Your job at this stage is to check your work and ensure that the diffs have been generated correctly based on the existing plan, not to increase the scope of the plan or add new tasks beyond fixing any problems in the diffs.+You do NOT need to list any problems if there are no clear issues that fit the above criteria. In many cases, there will be no problems.-If there are no problems, state in your own words that the plan appears to have been generated correctly and is now complete. If there are no problems, be very succinct. Don't summarize the plan or the diffs, or add additional detail. Just state in a few words that the plan is complete.+If there are no problems that fit the above criteria, state in your own words that the plan appears to have been generated correctly and is now complete. If there are no problems, be very succinct. Don't summarize the plan or the diffs, or add additional detail. Just state in a few words that the plan is complete.If there are problems, explain the problems and make a plan to fix them. You can use multiple responses to fix all the problems if necessary. If you've identified problems, don't skip any—fix them all thoroughly and don't stop until the plan is correct.@@ -327,45 +467,6 @@ UNDER NO CIRCUMSTANCES should you output code blocks or end your response with "var ChatOnlyPromptTokens int-func init() {- var err error- CreateSysMsgNumTokens, err = shared.GetNumTokens(SysCreate)-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for sys msg: %v", err))- }-- PromptWrapperTokens, err = shared.GetNumTokens(fmt.Sprintf(promptWrapperFormatStr, ""))-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for prompt wrapper: %v", err))- }-- AutoContinuePromptTokens, err = shared.GetNumTokens(AutoContinuePrompt)-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for auto continue prompt: %v", err))- }-- VerifyDiffsPromptTokens, err = shared.GetNumTokens(VerifyDiffsPrompt)-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for verify diffs prompt: %v", err))- }-- DebugPromptTokens, err = shared.GetNumTokens(DebugPrompt)-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for debug prompt: %v", err))- }-- ChatOnlyPromptTokens, err = shared.GetNumTokens(ChatOnlyPrompt)-- if err != nil {- panic(fmt.Sprintf("Error getting number of tokens for chat only prompt: %v", err))- }-}-const UpdateFormatPrompt = `You ABSOLUTELY MUST *ONLY* USE the comment "// ... existing code ..." (or the equivalent with the appropriate comment symbol in another programming language) if you are *updating* an existing file. DO NOT use it when you are creating a new file. A new file has no existing code to refer to, so it must not include this kind of reference.@@ -989,9 +1090,154 @@ func main() {Now the code before and after the change is accounted for.+Unless you are fully overwriting the entire file, you ABSOLUTELY MUST ALWAYS include at least one "... existing code ..." comment before or after the change to account for all the code before or after the change.++*++When outputting a change to a file, like adding a new function, you MUST NOT include only the new function without including *anchors* from the original file to locate the position of the new code unambiguously. For example, if the original file looks like this:++---+function someFunction() {+ console.log("someFunction")+ const res = await fetch("https://example.com")+ processResponse(res)+ return res+}++function processResponse(res) {+ console.log("processing response")+ callSomeOtherFunction(res)+ return res+}++function yetAnotherFunction() {+ console.log("yetAnotherFunction")+}++function callSomething() {+ console.log("callSomething")+ await logSomething()+ return "something"+}+---++DO NOT output a file block like this:++---+// ... existing code ...++function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+}++// ... existing code ...+---++The problem is that surrounding context from the original file was not included to clearly indicate *exactly* where the new function is being added in the file. Instead, do this:++---+// ... existing code ...++function processResponse(res) {+ // ... existing code ...+}++function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+}++// ... existing code ...+---++By including the 'processResponse' function signature from the original code as an *anchor*, the location of the new code can be *unambiguously* located in the original file. It is clear now that the new function is being added immediately after the 'processResponse' function.++It's EXTREMELY IMPORTANT that every file block that is *updating* an existing file includes at least one anchor that maps the lines from the original file to the lines in the file block so that the changes can be unambiguously located in the original file, and applied correctly.++Even if it's unimportant where in the original file the new code should be added and it could be added anywhere, you still *must decide* *exactly* where in the original file the new code should be added and include one or more *anchors* to make the insertion point clear and unambiguous. Do NOT leave out anchors for a file update under any circumstances.+*When writing an "... existing code ..." comment, you MUST use the correct comment symbol for the programming language. For example, if you are writing a plan in Python, Ruby, or Bash, you MUST use '# ... existing code ...' instead of '// ... existing code ...'. If you're writing HTML, you MUST use '<!-- ... existing code ... -->'. If you're writing jsx, tsx, svelte, or another language where the correct comment symbol(s) depend on where in the code you are, use the appropriate comment symbol(s) for where that comment is placed in the file. If you're in a javascript block of a jsx file, use '// ... existing code ...'. If you're in a markup block of a jsx file, use '{/* ... existing code ... */}'.Again, if you are writing a plan in a language that does not use '//' for comments, you absolutely must always use the appropriate comment symbol or symbols for that language instead of '//'. It is critically important that comments are ALWAYS written correctly for the language you are writing in.`++const ChangeExplanationPrompt = `+Prior to any file block that is *updating* an existing file in context, you MUST briefly explain the change in the following format:++I'll [action explanation].++'action explanation' can take one of the following forms:+- 'add [new code description] between [specific code or structure in original file] and [specific code or structure in original file]'+- 'add [new code description] between the start of the file and [specific code or structure in original file]'+- 'add [new code description] between [specific code or structure in original file] and the end of the file'+- 'overwrite the entire file with [new code description]'+- 'replace code between [specific code or structure in original file] and [specific code or structure in original file] with [new code description]'+- 'remove code between [specific code or structure in original file] and [specific code or structure in original file]'++You ABSOLUTELY MUST use one of the above formats exactly as described, and EVERY file block that updates an existing file in context MUST *ALWAYS* be preceded with an explanation of the change in this *exact* format. Use the EXACT wording as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY!++When referring to the start of the file, use the exact language 'the start of the file'.++When referring to the end of the file, use the exact language 'the end of the file'.++Do NOT leave off any part of the explanation as described above. Do NOT output something like: 'I'll add the doRequest method to the class' or 'I'll add the types for making the api call'. These do NOT exactly match one of the above formats. Instead, you MUST output the full explanation as described above like:+- I'll add the ` + "`doRequest`" + ` method between the constructor method and the ` + "`getUser`" + ` method.+- I'll add the types for making the api call between the imports and the ` + "`init`" + ` method.+- I'll overwrite the entire file with new code for the ` + "`update`" + ` CLI command.+- I'll add the ` + "`update`" + ` function between the ` + "`get`" + ` and the end of the file.++You ABSOLUTELY MUST use this template EXACTLY as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY!++When creating a *new* file, do NOT include this explanation.++*++If a file is being *updated* and the above explanation does not indicate that the file is being *overwritten* or that the change is being inserted at the *start* of the file, then the file block ABSOLUTELY ALWAYS MUST begin with an "... existing code ..." comment to account for all the code before the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.++If a file is being *updated* and the above explanation indicates that the file is being *overwritten* or that the change is being inserted at the *end* of the file, then the file block ABSOLUTELY ALWAYS MUST end with an "... existing code ..." comment to account for all the code after the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.++Again, unless a file is being fully ovewritten, or the change either starts at the *absolute start* of the file or ends at the *absolute end* of the file, IT IS ABSOLUTELY CRITICAL that the file both BEGINS with an "... existing code ..." comment and ENDS with an "... existing code ..." comment.++If a file must begin with an "... existing code ..." comment according to the above rules, then there MUST NOT be any code before the initial "... existing code ..." comment.++If a file must end with an "... existing code ..." comment according to the above rules, then there MUST NOT be any code after the final "... existing code ..." comment.++Again, if the change *does not* end at the *absolute end* of the file, then the LAST LINE of the file block MUST be an "... existing code ..." comment. Ending the file block like this:++---+// ... existing code ...++func (a *Api) NewMethod() {+ callExistingMethod()+}++func (a *Api) LoadContext(planId, branch string, req+ shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {+ // ... existing code ...+}+---++is NOT CORRECT, because the last line is not an "... existing code ..." comment—it is rather the '}' closing bracket of the function. Instead, it must be:++---+// ... existing code ...++func (a *Api) NewMethod() {+ callExistingMethod()+}++func (a *Api) LoadContext(planId, branch string, req+ shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError) {+ // ... existing code ...+}++// ... existing code ...+---++Now the final line is an "... existing code ..." comment, which is correct.+`diff --git a/app/server/model/prompts/summary.go b/app/server/model/prompts/summary.goindex 38bb1dea..e9b999c3 100644--- a/app/server/model/prompts/summary.go+++ b/app/server/model/prompts/summary.go@@ -42,6 +42,8 @@ Based on the existing summary and the conversation so far, make a summary of the- Next, if the plan has been broken down into subtasks, include ALL those subtasks *verbatim* in the summary as a numbered list, then mark whether each subtask has been implemented in code during the conversation. *Subtasks MUST ALWAYS be numbered.* You must include ALL subtasks, even if they have not been mentioned in the latest messages. If this conversation began with an existing summary, include ALL the subtasks from the existing summary.+- If any subtask have a 'Uses:' list with a list of files from context, you MUST also include that 'Uses: ' list *verbatim* when adding the subtask to the summary.+- Mark whether each subtask has been implemented in code during the conversation. A subtask has been implemented if *ANY* code blocks related to it have been included in the conversation. Do not be overly strict. Mark a subtask as implemented if it has been dealt with at all during the conversation. If a subtask has been implemented, mark it as implemented in code in the summary.- If a subtask has been further broken down into more subtasks, you should include those subtasks in the summary as a numbered list nested under the parent subtask. Just as with subtasks, you should include the name and a brief description of each sub-subtask and mark whether each sub-subtask has been implemented in code during the conversation.diff --git a/app/server/routes/routes.go b/app/server/routes/routes.goindex 1d1f032d..d715c698 100644--- a/app/server/routes/routes.go+++ b/app/server/routes/routes.go@@ -143,4 +143,6 @@ func addApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/default_settings", handlers.UpdateDefaultSettingsHandler).Methods("PUT")r.HandleFunc(prefix+"/file_map", handlers.GetFileMapHandler).Methods("POST")++ r.HandleFunc(prefix+"/plans/{planId}/{branch}/auto_load_context", handlers.AutoLoadContextHandler).Methods("POST")}diff --git a/app/server/syntax/file_map.go b/app/server/syntax/file_map.goindex da711d9a..4d59885c 100644--- a/app/server/syntax/file_map.go+++ b/app/server/syntax/file_map.go@@ -72,48 +72,108 @@ func mapTraditional(node *tree_sitter.Node, content []byte) []Definition {node := cursor.CurrentNode()nodeType := node.Type()+ if verboseLogging {+ fmt.Println()+ fmt.Println("node", nodeType)+ fmt.Println("content", string(node.Content(content)))+ fmt.Println()+ }+// Check if this is a definition nodeif isDefinitionNode(nodeType) {+ if verboseLogging {+ fmt.Println("definition node", nodeType)+ }+def := Definition{Type: nodeType,Line: int(node.StartPoint().Row) + 1,}if isAssignmentNode(nodeType) {+ if verboseLogging {+ fmt.Println("assignment node", node.Content(content))+ }// Try different field names for identifiers// fmt.Printf("assignment node: %s\n", nodeType)sig := ""- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- // fmt.Printf("child: %s\n", child.Type())-- if strings.HasSuffix(child.Type(), "_spec") {- for j := 0; j < int(child.ChildCount()); j++ {- subChild := child.Child(j)- // fmt.Printf("sub child: %s\n", subChild.Type())- if subChild.Type() == "identifier" {- sig += string(subChild.Content(content)) + " "- }++ assignmentBoundary := findAssignmentBoundary(node)++ if assignmentBoundary != nil {+ start := node.StartByte()+ end := assignmentBoundary.StartByte()+ sig = string(content[start:end])+ sig = strings.TrimSuffix(strings.TrimSpace(sig), "=")+ } else {+ identifiers := findIdentifier(node)+ if len(identifiers) > 0 {+ if verboseLogging {+ fmt.Println("found identifiers", len(identifiers))}- break++ start := node.StartByte()+ end := identifiers[len(identifiers)-1].EndByte()+ sig = string(content[start:end])} else {- sig += string(child.Content(content)) + " "+ if verboseLogging {+ fmt.Println("no identifier found", nodeType)+ }+ sig = string(node.Content(content)) + " "}}def.Signature = sig} else {+ if verboseLogging {+ fmt.Println("not assignment node", nodeType)+ }// Get signature (up to body)+if body := findImplementationBoundary(node); body != nil {start := node.StartByte()- end := body.StartByte()+ var end uint32+ if node == body {+ if verboseLogging {+ fmt.Println("node == body")+ }+ firstChild := firstDefinitionChild(body)+ if firstChild != nil {+ if verboseLogging {+ fmt.Println("firstChild != nil")+ fmt.Println("firstChild", firstChild.Type())+ fmt.Println("firstChild content", string(firstChild.Content(content)))+ }+ end = firstChild.StartByte()+ } else {+ if verboseLogging {+ fmt.Println("firstChild == nil")+ }+ end = body.EndByte()+ }+ } else {+ end = body.StartByte()+ }+ if verboseLogging {+ fmt.Println("start", start)+ fmt.Println("end", end)+ }def.Signature = string(content[start:end])+ if verboseLogging {+ fmt.Println("got signature", def.Signature)+ }// If this is a parent type node, recurse into the bodyif isParentNode(nodeType) {+ if verboseLogging {+ fmt.Println("recursing into body", nodeType)+ }def.Children = mapTraditional(body, content)}} else {+ if verboseLogging {+ fmt.Println("no body found", nodeType)+ }def.Signature = string(node.Content(content))}}@@ -166,10 +226,12 @@ var parentNodeTypes = map[string]bool{"module_definition": true, // Ruby"class_definition": true, // Python/Ruby"class_declaration": true, // Java/C#/TypeScript- "interface_declaration": true, // Java/TypeScript- "trait_definition": true, // Rust- "trait_declaration": true, // PHP- "impl_block": true, // Rust implementations+ // "interface_declaration": true, // Java/TypeScript+ // "trait_definition": true, // Rust+ // "trait_declaration": true, // PHP+ "impl_block": true, // Rust implementations+ // "type_declaration": true, // Go+ "const_declaration": true, // Go}func isParentNode(nodeType string) bool {@@ -183,8 +245,8 @@ var assignmentNodeTypes = map[string]bool{"variable_declaration": true,// Go- "var_declaration": true,- "const_declaration": true,+ "const_spec": true,+ "var_declaration": true,// JS/TS"lexical_declaration": true,@@ -225,7 +287,7 @@ func isAssignmentNode(nodeType string) bool {}// Implementation boundary detection-var bodyNodeTypes = map[string]bool{+var implBodyNodeTypes = map[string]bool{"block": true,"body": true,"suite": true,@@ -234,19 +296,78 @@ var bodyNodeTypes = map[string]bool{"function_body": true,"do_block": true,"implementation": true,- "field_declaration_list": true,+ "field_declaration_list": true, // Go+ "const_declaration": true, // Go+ "method_elem": true,+}++var assignmentBodyNodeTypes = map[string]bool{+ "literal_value": true,+ "expression_list": true,}func findImplementationBoundary(node *tree_sitter.Node) *tree_sitter.Node {+ if implBodyNodeTypes[node.Type()] {+ return node+ }+for i := 0; i < int(node.ChildCount()); i++ {child := node.Child(i)- if bodyNodeTypes[child.Type()] {++ if implBodyNodeTypes[child.Type()] {+ return child+ } else {+ found := findImplementationBoundary(child)+ if found != nil {+ return found+ }+ }+ }+ return nil+}++func findIdentifier(node *tree_sitter.Node) []*tree_sitter.Node {+ t := node.Type()+ if t == "identifier" || strings.HasSuffix(t, "_identifier") {+ return []*tree_sitter.Node{node}+ }++ nodes := []*tree_sitter.Node{}+ for i := 0; i < int(node.ChildCount()); i++ {+ child := node.Child(i)+ found := findIdentifier(child)+ if found != nil {+ nodes = append(nodes, found...)+ }+ }+ return nodes+}++func firstDefinitionChild(node *tree_sitter.Node) *tree_sitter.Node {+ for i := 0; i < int(node.ChildCount()); i++ {+ child := node.Child(i)+ if isDefinitionNode(child.Type()) {return child}}return nil}+func findAssignmentBoundary(node *tree_sitter.Node) *tree_sitter.Node {+ if assignmentBodyNodeTypes[node.Type()] {+ return node+ }++ for i := 0; i < int(node.ChildCount()); i++ {+ child := node.Child(i)+ found := findAssignmentBoundary(child)+ if found != nil {+ return found+ }+ }+ return nil+}+// Get preceding commentsfunc getPrecedingComments(node *tree_sitter.Node, content []byte) []string {var comments []stringdiff --git a/app/server/syntax/map_cli/go.mod b/app/server/syntax/map_cli/go.modindex 5e52d987..ff355dfd 100644--- a/app/server/syntax/map_cli/go.mod+++ b/app/server/syntax/map_cli/go.mod@@ -1,12 +1,24 @@module mapper-go 1.21.3+go 1.23.3replace plandex-server => ../../+replace github.com/plandex/plandex/shared => ../../../shared+require plandex-server v0.0.0-00010101000000-000000000000require (github.com/davecgh/go-spew v1.1.1 // indirect+ github.com/dlclark/regexp2 v1.11.4 // indirect+ github.com/google/uuid v1.6.0 // indirect+ github.com/mattn/go-runewidth v0.0.16 // indirect+ github.com/olekukonko/tablewriter v0.0.5 // indirect+ github.com/pkoukk/tiktoken-go v0.1.7 // indirect+ github.com/plandex/plandex/shared v0.0.0-00010101000000-000000000000 // indirect+ github.com/rivo/uniseg v0.4.7 // indirect+ github.com/sashabaranov/go-openai v1.35.6 // indirect+ github.com/shopspring/decimal v1.4.0 // indirectgithub.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6 // indirect+ golang.org/x/image v0.22.0 // indirect)diff --git a/app/server/syntax/map_cli/go.sum b/app/server/syntax/map_cli/go.sumindex 0447717d..88a925c9 100644--- a/app/server/syntax/map_cli/go.sum+++ b/app/server/syntax/map_cli/go.sum@@ -1,8 +1,26 @@github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=+github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=+github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=+github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=+github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=+github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=+github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=+github.com/pkoukk/tiktoken-go v0.1.7 h1:qOBHXX4PHtvIvmOtyg1EeKlwFRiMKAcoMp4Q+bLQDmw=+github.com/pkoukk/tiktoken-go v0.1.7/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=+github.com/sashabaranov/go-openai v1.35.6 h1:oi0rwCvyxMxgFALDGnyqFTyCJm6n72OnEG3sybIFR0g=+github.com/sashabaranov/go-openai v1.35.6/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=+github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=+github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6 h1:mtD4ESyObQZnRVxHFcaYp2d7jMBDa4WJRXSB1Vszj+A=github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=@@ -11,6 +29,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=+golang.org/x/image v0.22.0 h1:UtK5yLUzilVrkjMAZAZ34DXGpASN8i8pj8g+O+yd10g=+golang.org/x/image v0.22.0/go.mod h1:9hPFhljd4zZ1GNSIZJ49sqbp45GKK9t6w+iXvGqZUz4=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=diff --git a/app/server/syntax/structural_edits.go b/app/server/syntax/structural_edits.goindex aea6c131..4acf1df8 100644--- a/app/server/syntax/structural_edits.go+++ b/app/server/syntax/structural_edits.go@@ -210,6 +210,7 @@ func ApplyChanges(var currentPNodeMatches boollastLineMatched := true+ foundAnyAnchor := falsesetOLineNum := func(n int) {oLineNum = n@@ -312,12 +313,26 @@ func ApplyChanges(}} else {if verboseLogging {- fmt.Printf("numRefs > 1, refOriginalParent: %s\n", refOriginalParent.Type())+ fmt.Printf("numRefs > 1, refOriginalParent: %s, eof: %v\n", refOriginalParent.Type(), eof)fmt.Printf("refOriginalParent.Content(originalBytes):\n%q\n", refOriginalParent.Content(originalBytes))fmt.Printf("numRefs: %d, oLineNum: %d\n", numRefs, oLineNum)}- sections := getSections(refOriginalParent, originalBytes, numRefs, refStart, oLineNum)+ var upToLine int+ if eof {+ upToLine = len(originalLines)+ } else {+ upToLine = oLineNum+ }++ sections := getSections(+ refOriginalParent,+ originalBytes,+ numRefs,+ refStart,+ upToLine,+ foundAnyAnchor,+ )for i, section := range sections {if verboseLogging {@@ -453,6 +468,7 @@ func ApplyChanges(// find next line in original that matchesanchor := findNextAnchor(pLine, pLineNum, pNode, oLineNum-1)if anchor != nil {+ foundAnyAnchor = trueif verboseLogging {fmt.Println("anchor found")fmt.Printf("anchor.Close: %d, anchor.Open: %d\n", anchor.Close, anchor.Open)@@ -572,7 +588,7 @@ func ApplyChanges(return b.String(), nil}-func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine, upToLine int) []TreeSitterSection {+func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine, upToLine int, foundAnyAnchor bool) []TreeSitterSection {sections := make([]TreeSitterSection, numSections)structures := [][]*tree_sitter.Node{}latestStructure := []*tree_sitter.Node{}@@ -603,19 +619,26 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,if startLineNum < fromLine {if verboseLogging {+ fmt.Println("startLineNum < fromLine, skipping")fmt.Printf("skipping lineNum: %d | before fromLine: %d\n", startLineNum, fromLine)}if !cursor.GoToNextSibling() {+ if verboseLogging {+ fmt.Println("no next sibling, breaking")+ }break}continue}- if startLineNum == parentFirstLineNum {+ if startLineNum == parentFirstLineNum && foundAnyAnchor {if verboseLogging {fmt.Printf("skipping first line\n")}if !cursor.GoToNextSibling() {+ if verboseLogging {+ fmt.Println("no next sibling, breaking")+ }break}continue@@ -623,6 +646,7 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,if endLineNum > upToLine {if verboseLogging {+ fmt.Println("endLineNum > upToLine, breaking")fmt.Printf("upToLine: %d, endLineNum: %d, node.Type(): %s\n", upToLine, endLineNum, node.Type())toLog := node.Content(bytes)@@ -636,6 +660,9 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,}if endLineNum == parentEndLineNum && !isStructuralNode(node) {+ if verboseLogging {+ fmt.Println("endLineNum == parentEndLineNum && !isStructuralNode(node), breaking")+ }break}@@ -656,10 +683,16 @@ func getSections(parent *tree_sitter.Node, bytes []byte, numSections, fromLine,}if !cursor.GoToNextSibling() {+ if verboseLogging {+ fmt.Println("no next sibling, breaking")+ }break}}if len(latestStructure) > 0 {+ if verboseLogging {+ fmt.Println("appending latestStructure to structures")+ }structures = append(structures, latestStructure)}}diff --git a/app/server/syntax/structural_edits_test.go b/app/server/syntax/structural_edits_test.goindex 3e46056f..b408b99d 100644--- a/app/server/syntax/structural_edits_test.go+++ b/app/server/syntax/structural_edits_test.go@@ -1104,9 +1104,168 @@ class MetricsService(},parser: getParserForLanguage("scala"),},++ {+ name: "top-level ambiguous",+ original: `+ function someFunction() {+ console.log("someFunction")+ const res = await fetch("https://example.com")+ processResponse(res)+ return res+ }++ function processResponse(res) {+ console.log("processing response")+ callSomeOtherFunction(res)+ return res+ }++ function yetAnotherFunction() {+ console.log("yetAnotherFunction")+ }++ function callSomething() {+ console.log("callSomething")+ await logSomething()+ return "something"+ }+ `,+ proposed: `+ // ... existing code ...++ function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+ }++ // ... existing code ...+ `,+ references: []Reference{+ 2, 10,+ },+ want: `+ function someFunction() {+ console.log("someFunction")+ const res = await fetch("https://example.com")+ processResponse(res)+ return res+ }++ function processResponse(res) {+ console.log("processing response")+ callSomeOtherFunction(res)+ return res+ }++ function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+ }++ function yetAnotherFunction() {+ console.log("yetAnotherFunction")+ }++ function callSomething() {+ console.log("callSomething")+ await logSomething()+ return "something"+ }+ `,+ parser: getParserForLanguage("javascript"),+ },++ {+ name: "top-level with anchors",+ original: `+ function someFunction() {+ console.log("someFunction")+ const res = await fetch("https://example.com")+ processResponse(res)+ return res+ }++ function processResponse(res) {+ console.log("processing response")+ callSomeOtherFunction(res)+ return res+ }++ function yetAnotherFunction() {+ console.log("yetAnotherFunction")+ doStuff()+ }++ function callSomething() {+ console.log("callSomething")+ await logSomething()+ return "something"+ }+ `,+ proposed: `+ // ... existing code ...++ function processResponse(res) {+ // ... existing code ...+ }++ function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+ }++ function yetAnotherFunction() {+ // ... existing code ...+ }++ // ... existing code ...+ `,+ references: []Reference{+ 2, 5, 15, 18,+ },+ want: `+ function someFunction() {+ console.log("someFunction")+ const res = await fetch("https://example.com")+ processResponse(res)+ return res+ }++ function processResponse(res) {+ console.log("processing response")+ callSomeOtherFunction(res)+ return res+ }++ function newFunction() {+ console.log("newFunction")+ const res = await callSomething()+ return res+ }++ function yetAnotherFunction() {+ console.log("yetAnotherFunction")+ doStuff()+ }++ function callSomething() {+ console.log("callSomething")+ await logSomething()+ return "something"+ }+ `,+ parser: getParserForLanguage("javascript"),+ },}for _, tt := range tests {+ // if tt.name != "top-level with anchor after" {+ // continue+ // }t.Run(tt.name, func(t *testing.T) {anchorLines := map[int]int{}if tt.anchorLines != nil {diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.goindex 3dc1a419..26ff4dd1 100644--- a/app/server/types/active_plan.go+++ b/app/server/types/active_plan.go@@ -13,9 +13,7 @@ import ("github.com/plandex/plandex/shared")-const MaxStreamRate = 50 * time.Millisecond--// const MaxConcurrentBuildStreams = 3 // otherwise we get EOF errors from openai+const MaxStreamRate = 100 * time.Millisecondtype ActiveBuild struct {ReplyId string@@ -76,11 +74,14 @@ type ActivePlan struct {ModelStreamId stringMissingFilePath stringMissingFileResponseCh chan shared.RespondMissingFileChoice+ AutoContext bool+ AutoLoadContextCh chan struct{}AllowOverwritePaths map[string]boolSkippedPaths map[string]boolStoredReplyIds []stringDidEditFiles boolDidVerifyDiff bool+ IsVerifyingDiff boolsubscriptions map[string]*subscriptionsubscriptionMu sync.Mutex@@ -91,7 +92,7 @@ type ActivePlan struct {streamMessageBuffer []shared.StreamMessage}-func NewActivePlan(orgId, userId, planId, branch, prompt string, buildOnly bool) *ActivePlan {+func NewActivePlan(orgId, userId, planId, branch, prompt string, buildOnly, autoContext bool) *ActivePlan {ctx, cancel := context.WithCancel(context.Background())// child context for model stream so we can cancel it separately if neededmodelStreamCtx, cancelModelStream := context.WithCancel(ctx)@@ -120,6 +121,8 @@ func NewActivePlan(orgId, userId, planId, branch, prompt string, buildOnly bool)IsBuildingByPath: map[string]bool{},StreamDoneCh: make(chan *shared.ApiError),MissingFileResponseCh: make(chan shared.RespondMissingFileChoice),+ AutoContext: autoContext,+ AutoLoadContextCh: make(chan struct{}),AllowOverwritePaths: map[string]bool{},SkippedPaths: map[string]bool{},streamCh: make(chan string),@@ -364,6 +367,7 @@ func (ap *ActivePlan) ShouldVerifyDiff() bool {// len(ap.BuiltFiles) > 3)return !ap.BuildOnly &&+ !ap.IsVerifyingDiff &&!ap.DidVerifyDiff &&(len(ap.BuiltFiles) > 0 || len(ap.IsBuildingByPath) > 0) &&(ap.DidEditFiles || len(ap.BuiltFiles) > 3) // verify diff if we edited any files or built more than 3 new files—unlikely to have errors otherwisediff --git a/app/shared/context.go b/app/shared/context.goindex 40363dd3..d900c571 100644--- a/app/shared/context.go+++ b/app/shared/context.go@@ -86,6 +86,20 @@ func TableForLoadContext(contexts []*Context) string {return tableString.String()}+func MarkdownTableForLoadContext(contexts []*Context) string {+ var sb strings.Builder+ sb.WriteString("| Name | Type | 🪙 |\n")+ sb.WriteString("|------|------|----|\n")++ for _, context := range contexts {+ t, icon := context.TypeAndIcon()+ sb.WriteString(fmt.Sprintf("| %s %s | %s | +%d |\n",+ icon, context.Name, t, context.NumTokens))+ }++ return sb.String()+}+func SummaryForLoadContext(contexts []*Context, tokensAdded, totalTokens int) string {var hasNote booldiff --git a/app/shared/file_maps.go b/app/shared/file_maps.goindex eb62f812..b8de6fda 100644--- a/app/shared/file_maps.go+++ b/app/shared/file_maps.go@@ -15,7 +15,11 @@ func (m FileMapBodies) CombinedMap() string {sort.Strings(paths)for _, path := range paths {body := m[path]- fileHeading := fmt.Sprintf("### %s\n", path)+ body = strings.TrimSpace(body)+ if body == "" {+ continue+ }+ fileHeading := fmt.Sprintf("\n### %s\n", path)combinedMap.WriteString(fileHeading)combinedMap.WriteString(body)combinedMap.WriteString("\n")diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex 1e0d978f..52458250 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -122,6 +122,7 @@ type TellPlanRequest struct {IsUserContinue bool `json:"isUserContinue"`IsUserDebug bool `json:"isUserDebug"`IsChatOnly bool `json:"isChatOnly"`+ AutoContext bool `json:"autoContext"`ApiKey string `json:"apiKey"` // deprecatedEndpoint string `json:"endpoint"` // deprecatedApiKeys map[string]string `json:"apiKeys"`diff --git a/app/shared/stream.go b/app/shared/stream.goindex b512064d..934e3d19 100644--- a/app/shared/stream.go+++ b/app/shared/stream.go@@ -18,6 +18,7 @@ const (StreamMessageRepliesFinished StreamMessageType = "repliesFinished"StreamMessageBuildInfo StreamMessageType = "buildInfo"StreamMessagePromptMissingFile StreamMessageType = "promptMissingFile"+ StreamMessageLoadContext StreamMessageType = "loadContext"StreamMessageAborted StreamMessageType = "aborted"StreamMessageFinished StreamMessageType = "finished"StreamMessageError StreamMessageType = "error"@@ -30,15 +31,16 @@ type StreamMessage struct {ReplyChunk string `json:"replyChunk,omitempty"`- BuildInfo *BuildInfo `json:"buildInfo,omitempty"`- Description *ConvoMessageDescription `json:"description,omitempty"`- Error *ApiError `json:"error,omitempty"`- MissingFilePath string `json:"missingFilePath,omitempty"`- ModelStreamId string `json:"modelStreamId,omitempty"`-- InitPrompt string `json:"initPrompt,omitempty"`- InitReplies []string `json:"initReplies,omitempty"`- InitBuildOnly bool `json:"initBuildOnly,omitempty"`+ BuildInfo *BuildInfo `json:"buildInfo,omitempty"`+ Description *ConvoMessageDescription `json:"description,omitempty"`+ Error *ApiError `json:"error,omitempty"`+ MissingFilePath string `json:"missingFilePath,omitempty"`+ MissingFileAutoContext bool `json:"missingFileAutoContext,omitempty"`+ ModelStreamId string `json:"modelStreamId,omitempty"`+ LoadContextFiles []string `json:"loadContextFiles,omitempty"`+ InitPrompt string `json:"initPrompt,omitempty"`+ InitReplies []string `json:"initReplies,omitempty"`+ InitBuildOnly bool `json:"initBuildOnly,omitempty"`StreamMessages []StreamMessage `json:"streamMessages,omitempty"`}