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
collapsible build info for when many files are building. file build status backup polling loop for when finished messages are missed. for subtasks, defer to implementation message if completion marker is there. context stage output tweak.
Dane Schneider509f6f846b9d
diff --git a/app/cli/api/methods.go b/app/cli/api/methods.goindex 9ce5dd05..0e2214af 100644--- a/app/cli/api/methods.go+++ b/app/cli/api/methods.go@@ -2350,3 +2350,31 @@ func (a *Api) AutoLoadContext(ctx context.Context, planId, branch string, req shreturn &loadContextResponse, nil}++func (a *Api) GetBuildStatus(planId, branch string) (*shared.GetBuildStatusResponse, *shared.ApiError) {+ serverUrl := fmt.Sprintf("%s/plans/%s/%s/build_status", GetApiHost(), planId, branch)++ resp, err := authenticatedFastClient.Get(serverUrl)+ 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.GetBuildStatus(planId, branch)+ }+ return nil, apiErr+ }++ var respBody shared.GetBuildStatusResponse+ err = json.NewDecoder(resp.Body).Decode(&respBody)+ if err != nil {+ return nil, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error decoding response: %v", err)}+ }++ return &respBody, nil+}diff --git a/app/cli/stream_tui/model.go b/app/cli/stream_tui/model.goindex fb04776e..1d9dd6fc 100644--- a/app/cli/stream_tui/model.go+++ b/app/cli/stream_tui/model.go@@ -81,6 +81,9 @@ type streamUIModel struct {updateDebouncer *UpdateDebouncerautoLoadContextCancelFn context.CancelFunc++ buildViewCollapsed bool+ userExpandedBuild bool}type keymap = struct {@@ -100,9 +103,18 @@ type keymap = struct {func (m streamUIModel) Init() tea.Cmd {log.Println("Model Init start")m.mainViewport.MouseWheelEnabled = true- cmd := m.Tick()- log.Println("Model Init complete")- return cmd+ return tea.Batch(+ m.Tick(),+ m.pollBuildStatus(),+ )+}++type buildStatusPollMsg time.Time++func (m streamUIModel) pollBuildStatus() tea.Cmd {+ return tea.Every(5*time.Second, func(t time.Time) tea.Msg {+ return buildStatusPollMsg(t)+ })}func initialModel(prestartReply, prompt string, buildOnly bool) *streamUIModel {@@ -116,9 +128,10 @@ func initialModel(prestartReply, prompt string, buildOnly bool) *streamUIModel {buildSpinner.Spinner = spinner.MiniDotinitialState := streamUIModel{- buildOnly: buildOnly,- prompt: prompt,- reply: prestartReply,+ buildOnly: buildOnly,+ buildViewCollapsed: false,+ prompt: prompt,+ reply: prestartReply,keymap: keymap{quit: bubbleKey.NewBinding(bubbleKey.WithKeys("b", "ctrl+c"),diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.goindex 9ac2f8ae..6bbde480 100644--- a/app/cli/stream_tui/update.go+++ b/app/cli/stream_tui/update.go@@ -96,9 +96,9 @@ func (m streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.pageDown()case bubbleKey.Matches(msg, m.keymap.pageUp) && !m.promptingMissingFile:m.pageUp()- case bubbleKey.Matches(msg, m.keymap.up):+ case bubbleKey.Matches(msg, m.keymap.up) && m.building:m.up()- case bubbleKey.Matches(msg, m.keymap.down):+ case bubbleKey.Matches(msg, m.keymap.down) && m.building:m.down()case bubbleKey.Matches(msg, m.keymap.start) && !m.promptingMissingFile:m.scrollStart()@@ -110,6 +110,43 @@ func (m streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {default:m.resolveEscapeSequence(msg.String())}++ case buildStatusPollMsg:+ state := m.readState()+ log.Println("buildStatusPollMsg")++ numPaths := len(m.tokensByPath)+ numFinished := 0++ for _, isBuilt := range m.finishedByPath {+ if isBuilt {+ numFinished+++ }+ }++ // log.Printf("state.finished: %v, state.stopped: %v, state.background: %v, numPaths: %d, numFinished: %d", state.finished, state.stopped, state.background, numPaths, numFinished)++ if !state.finished && !state.stopped && !state.background && numPaths > 0 && numPaths != numFinished {+ // log.Println("build status poll - making api call")+ status, apiErr := api.Client.GetBuildStatus(lib.CurrentPlanId, lib.CurrentBranch)+ if apiErr != nil {+ // log.Println("build status poll error:", apiErr)+ return m, m.pollBuildStatus()+ }++ // log.Println("build status poll success")+ // log.Printf("status: %v", status)++ m.updateState(func() {+ for path, isBuilt := range status.BuiltFiles {+ isBuilding := status.IsBuildingByPath[path]+ if isBuilt && !isBuilding {+ m.finishedByPath[path] = true+ }+ }+ })+ }+ return m, m.pollBuildStatus()}return m, nil@@ -422,6 +459,15 @@ func (m *streamUIModel) streamUpdate(msg *shared.StreamMessage, deferUIUpdate bo})}+ // Auto-collapse if build info takes up too much space+ state = m.readState()+ if !state.userExpandedBuild && state.building {+ rows := len(m.getRows(false))+ m.updateState(func() {+ m.buildViewCollapsed = rows > 3+ })+ }+if !deferUIUpdate {m.updateViewportDimensions()}@@ -559,6 +605,11 @@ func (m *streamUIModel) up() {m.updateState(func() {m.missingFileSelectedIdx = max(m.missingFileSelectedIdx-1, 0)})+ } else {+ m.updateState(func() {+ m.buildViewCollapsed = false+ m.userExpandedBuild = true+ })}}@@ -569,6 +620,10 @@ func (m *streamUIModel) down() {m.updateState(func() {m.missingFileSelectedIdx = min(m.missingFileSelectedIdx+1, len(missingFileSelectOpts)-1)})+ } else {+ m.updateState(func() {+ m.buildViewCollapsed = true+ })}}diff --git a/app/cli/stream_tui/view.go b/app/cli/stream_tui/view.goindex 0821b242..74031d8e 100644--- a/app/cli/stream_tui/view.go+++ b/app/cli/stream_tui/view.go@@ -81,19 +81,95 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {style = lipgloss.NewStyle().Width(m.width).BorderStyle(lipgloss.NormalBorder()).BorderTop(true).BorderForeground(lipgloss.Color(borderColor))}- // log.Println("filePaths:", filePaths)- // log.Println("len(resRows):", len(resRows))+ if m.buildViewCollapsed {+ // Render collapsed view+ inProgress := 0+ total := len(m.tokensByPath)+ for path := range m.tokensByPath {+ if path == "_apply.sh" {+ total--+ continue+ }+ if !m.finishedByPath[path] {+ inProgress+++ }+ }++ _, hasApplyScript := m.tokensByPath["_apply.sh"]+ applyScriptFinished := m.finishedByPath["_apply.sh"]++ lbl := "file"+ if total > 1 {+ lbl = "files"+ }++ var summary string+ if total > 0 {+ summary = fmt.Sprintf(" %d %s", total, lbl)+ }+ if inProgress > 0 {+ summary += fmt.Sprintf(" • editing %d %s", inProgress, m.buildSpinner.View())+ }+ if hasApplyScript {+ if total > 0 {+ summary += " •"+ }+ if applyScriptFinished {+ summary += " 🚀 wrote commands"+ } else {+ summary += fmt.Sprintf(" 🚀 editing commands %s", m.buildSpinner.View())+ }+ }+ head := m.getBuildHeader(outputStatic)+ return style.Render(lipgloss.JoinVertical(lipgloss.Left, head, summary))+ }resRows := m.getRows(outputStatic)res := style.Render(strings.Join(resRows, "\n"))- // log.Println("\n\n", res, "\n\n")-return res}+func (m streamUIModel) didBuild() bool {+ return !(m.stopped || m.err != nil || m.apiErr != nil)+}++func (m streamUIModel) getBuildHeader(static bool) string {+ lbl := "Building plan "+ bgColor := color.BgGreen+ if static {+ if !m.didBuild() {+ lbl = "Build incomplete "+ bgColor = color.BgRed+ } else {+ lbl = "Built plan "+ }+ }++ head := color.New(bgColor, color.FgHiWhite, color.Bold).Sprint(" 🏗 ") + color.New(bgColor, color.FgHiWhite).Sprint(lbl)++ // Add collapse/expand hint+ var hint string+ if !static {+ hint = "↓ collapse"+ if m.buildViewCollapsed {+ hint = "↑ expand"+ }+ }+ padding := m.width - lipgloss.Width(head) - lipgloss.Width(hint) - 1 // 1 for space+ if padding > 0 {+ head += strings.Repeat(" ", padding) + hint+ }++ return head+}+func (m streamUIModel) getRows(static bool) []string {+ built := m.didBuild() && static++ head := m.getBuildHeader(static)+filePaths := make([]string, 0, len(m.tokensByPath))for filePath := range m.tokensByPath {// _apply.sh script goes last@@ -109,23 +185,6 @@ func (m streamUIModel) getRows(static bool) []string {filePaths = append(filePaths, "_apply.sh")}- lbl := "Building plan "- bgColor := color.BgGreen- built := false- if static {- // log.Printf("m.finished: %v, m.stopped: %v, len(m.finishedByPath): %d, len(m.tokensByPath): %d", m.finished, len(m.finishedByPath), len(m.tokensByPath))-- if m.stopped || m.err != nil || m.apiErr != nil {- lbl = "Build incomplete "- bgColor = color.BgRed- } else {- lbl = "Built plan "- built = true- }- }-- head := color.New(bgColor, color.FgHiWhite, color.Bold).Sprint(" 🏗 ") + color.New(bgColor, color.FgHiWhite).Sprint(lbl)-var rows [][]stringrows = append(rows, []string{})lineWidth := 0@@ -140,6 +199,7 @@ func (m streamUIModel) getRows(static bool) []string {label := filePathif filePath == "_apply.sh" {icon = "🚀"+ label = "commands"}block := fmt.Sprintf("%s %s", icon, label)diff --git a/app/cli/types/api.go b/app/cli/types/api.goindex 36c238cb..4b895ba6 100644--- a/app/cli/types/api.go+++ b/app/cli/types/api.go@@ -113,4 +113,5 @@ type ApiClient interface {GetFileMap(req shared.GetFileMapRequest) (*shared.GetFileMapResponse, *shared.ApiError)GetContextBody(planId, branch, contextId string) (*shared.GetContextBodyResponse, *shared.ApiError)AutoLoadContext(ctx context.Context, planId, branch string, req shared.LoadContextRequest) (*shared.LoadContextResponse, *shared.ApiError)+ GetBuildStatus(planId, branch string) (*shared.GetBuildStatusResponse, *shared.ApiError)}diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.goindex 86702b73..03c2c2a0 100644--- a/app/server/handlers/plans_exec.go+++ b/app/server/handlers/plans_exec.go@@ -477,6 +477,55 @@ func AutoLoadContextHandler(w http.ResponseWriter, r *http.Request) {log.Println("Successfully processed request for AutoLoadContextHandler")}+func GetBuildStatusHandler(w http.ResponseWriter, r *http.Request) {+ // logs are too chatty on this function, uncomment if you need to debug+ // log.Println("Received request for GetBuildStatusHandler", "ip:", host.Ip)++ vars := mux.Vars(r)+ planId := vars["planId"]+ branch := vars["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+ }++ response := shared.GetBuildStatusResponse{+ BuiltFiles: active.BuiltFiles,+ IsBuildingByPath: active.IsBuildingByPath,+ }++ bytes, err := json.Marshal(response)+ if err != nil {+ log.Printf("Error marshalling response: %v\n", err)+ http.Error(w, "Error marshalling response", http.StatusInternalServerError)+ return+ }++ w.Write(bytes)++ // log.Println("Successfully processed request for GetBuildStatusHandler")+}+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/plan/exec_status.go b/app/server/model/plan/exec_status.goindex 6f2b6755..49a0d864 100644--- a/app/server/model/plan/exec_status.go+++ b/app/server/model/plan/exec_status.go@@ -41,44 +41,50 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage striif strings.Contains(currentMessage, completionMarker) {log.Printf("[ExecStatus] ✓ Subtask completion marker found")-- var potentialProblem bool-- if len(state.chunkProcessor.replyOperations) == 0 {- log.Printf("[ExecStatus] ✗ Subtask completion marker found, but there are no operations to execute")- potentialProblem = true- } else {- wroteToPaths := map[string]bool{}- for _, op := range state.chunkProcessor.replyOperations {- if op.Type == shared.OperationTypeFile {- wroteToPaths[op.Path] = true- }- }-- for _, path := range state.currentSubtask.UsesFiles {- if !wroteToPaths[path] {- log.Printf("[ExecStatus] ✗ Subtask completion marker found, but the operations did not write to the file %q from the 'Uses' list", path)- potentialProblem = true- break- }- }- }-- if !potentialProblem {- log.Printf("[ExecStatus] ✓ Subtask completion marker found and no potential problem - will mark as completed")-- return execStatusShouldContinueResult{- subtaskFinished: true,- }, nil- } else if state.currentSubtask.NumTries >= 1 {- log.Printf("[ExecStatus] ✓ Subtask completion marker found, but the operations are questionable -- marking it done anyway since it's the second try and we can't risk an infinite loop")-- return execStatusShouldContinueResult{- subtaskFinished: true,- }, nil- } else {- log.Printf("[ExecStatus] ✗ Subtask completion marker found, but the operations are questionable -- will verify with LLM call")- }+ return execStatusShouldContinueResult{+ subtaskFinished: true,+ }, nil++ // NOTE: tried using an LLM to verify "suspicious" subtask completions, but in practice led to too many extra LLM calls and disagreement cycles between agent roles (it's finished. no it's note! etc.)+ // now just going back to trusting the completion marker... basically it's better to err on the side of marking tasks done.++ // var potentialProblem bool++ // if len(state.chunkProcessor.replyOperations) == 0 {+ // log.Printf("[ExecStatus] ✗ Subtask completion marker found, but there are no operations to execute")+ // potentialProblem = true+ // } else {+ // wroteToPaths := map[string]bool{}+ // for _, op := range state.chunkProcessor.replyOperations {+ // if op.Type == shared.OperationTypeFile {+ // wroteToPaths[op.Path] = true+ // }+ // }++ // for _, path := range state.currentSubtask.UsesFiles {+ // if !wroteToPaths[path] {+ // log.Printf("[ExecStatus] ✗ Subtask completion marker found, but the operations did not write to the file %q from the 'Uses' list", path)+ // potentialProblem = true+ // break+ // }+ // }+ // }++ // if !potentialProblem {+ // log.Printf("[ExecStatus] ✓ Subtask completion marker found and no potential problem - will mark as completed")++ // return execStatusShouldContinueResult{+ // subtaskFinished: true,+ // }, nil+ // } else if state.currentSubtask.NumTries >= 1 {+ // log.Printf("[ExecStatus] ✓ Subtask completion marker found, but the operations are questionable -- marking it done anyway since it's the second try and we can't risk an infinite loop")++ // return execStatusShouldContinueResult{+ // subtaskFinished: true,+ // }, nil+ // } else {+ // log.Printf("[ExecStatus] ✗ Subtask completion marker found, but the operations are questionable -- will verify with LLM call")+ // }} else {log.Printf("[ExecStatus] ✗ No subtask completion marker found in message")}diff --git a/app/server/model/prompts/architect_context.go b/app/server/model/prompts/architect_context.goindex 5b7c1957..d02fc5e3 100644--- a/app/server/model/prompts/architect_context.go+++ b/app/server/model/prompts/architect_context.go@@ -43,7 +43,7 @@ YOUR TASK:- State "No context needs to be loaded." along with a brief conversational response and output <PlandexFinish/>If context needed:- a) "### Context Categories"+ a) "### Categories"- List categories of context to activate- One line per category- No file paths or symbols here@@ -104,7 +104,7 @@ In response to the user's latest prompt, do the following IN ORDER:4. If you already have enough information from the project map to make a detailed plan or respond effectively to the user and so you won't need to load any additional context, then skip step 5 and output a <PlandexFinish/> immediately after steps 1 and 2 above.5. Otherwise, you MUST output:- a) A section titled "### Context Categories" listing one or more categories of context that are relevant to the user's task or message. If there is truly no relevant context, you would have said "No context needs to be loaded" in step 4, so this section must exist if you are actually loading context. Do not list files here—just categories.+ a) A section titled "### Categories" listing one or more categories of context that are relevant to the user's task or message. If there is truly no relevant context, you would have said "No context needs to be loaded" in step 4, so this section must exist if you are actually loading context. Do not list files here—just categories.b) A section titled "### Files" enumerating the relevant files and symbols from the codebase map that correspond to the categories you listed. See additional rules below.c) Immediately after the '### Files' list, output a <PlandexFinish/> tag. ***Do not output any text after <PlandexFinish/>.***@@ -156,14 +156,14 @@ If you need context:func GetAutoContextShared(params CreatePromptParams, tellMode bool) string {s := `-- In a section titled '### Context Categories', list one or more categories of context that are relevant to the user's task, question, or message. For example, if the user is asking you to implement an API endpoint, you might list 'API endpoints', 'database operations', 'frontend code', 'utilities', and so on. Make sure any and all relevant categories are included, but don't include more categories than necessary—if only a single category is relevant, then only list that one. Do not include file paths, symbols, or explanations—only the categories.`+- In a section titled '### Categories', list one or more categories of context that are relevant to the user's task, question, or message. For example, if the user is asking you to implement an API endpoint, you might list 'API endpoints', 'database operations', 'frontend code', 'utilities', and so on. Make sure any and all relevant categories are included, but don't include more categories than necessary—if only a single category is relevant, then only list that one. Do not include file paths, symbols, or explanations—only the categories.`if tellMode && params.ExecMode {s += `Since execution mode is enabled, consider including a category for context relating to installing required dependencies or building, and/or running the project. Adapt this to the user's project, task, and prompt. Don't force it—only include this category if it makes senses.`}s += `-- Using the project map in context, output a '### Files' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path (surrounded by backticks) and the names of all potentially relevant symbols. File paths *absolutely must* be surrounded by backticks like this: ` + "`path/to/file.go`" + `. Any symbols that are referred to in the user's prompt must be included. You MUST organize the list by category using the categories from the '### Context Categories' section—ensure each category is represented in the list. When listing symbols, output just the name of the symbol, not it's full signature (e.g. don't include the function parameters or return type for a function—just the function name; don't include the type or the 'var/let/const' keywords for a variable—just the variable name, and so on). Output the symbols as a comma separated list in a single paragraph for each file. You MUST include relevant symbols (and associated file paths) for each category from the '### Context Categories' section. Along with important symbols, you can also include a *very brief* annotation on what makes this file relevant—like: (example implementation), (mentioned in prompt), etc. At the end of the list, output a <PlandexFinish/> tag.+- Using the project map in context, output a '### Files' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path (surrounded by backticks) and the names of all potentially relevant symbols. File paths *absolutely must* be surrounded by backticks like this: ` + "`path/to/file.go`" + `. Any symbols that are referred to in the user's prompt must be included. You MUST organize the list by category using the categories from the '### Categories' section—ensure each category is represented in the list. When listing symbols, output just the name of the symbol, not it's full signature (e.g. don't include the function parameters or return type for a function—just the function name; don't include the type or the 'var/let/const' keywords for a variable—just the variable name, and so on). Output the symbols as a comma separated list in a single paragraph for each file. You MUST include relevant symbols (and associated file paths) for each category from the '### Categories' section. Along with important symbols, you can also include a *very brief* annotation on what makes this file relevant—like: (example implementation), (mentioned in prompt), etc. At the end of the list, output a <PlandexFinish/> tag.- ALL file paths in the '### Files' section ABSOLUTELY MUST be in the codebase map. Do NOT UNDER ANY CIRCUMSTANCES include files that are not in the codebase map. File paths in the codebase map are always preceeded by '###'. You must ONLY include these files. Do NOT include hypothetical files based on common project layouts. ONLY mention files that are *explicitly* listed in the codebase map.@@ -205,7 +205,7 @@ When assessing relevant context, you MUST follow these rules:- Load ALL files containing utilities you might needExample: If using string formatting utilities, load the utils file with those functions-When considering relevant categories in the '### Context Categories' and relevant symbols in the '### Files' sections:+When considering relevant categories in the '### Categories' and relevant symbols in the '### Files' sections:1. Look for naming patterns:- Files with similar prefixes or suffixesdiff --git a/app/server/routes/routes.go b/app/server/routes/routes.goindex 23d17292..d5545e3f 100644--- a/app/server/routes/routes.go+++ b/app/server/routes/routes.go@@ -164,4 +164,6 @@ func addProxyableApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/plans/{planId}/{branch}/respond_missing_file", handlers.RespondMissingFileHandler).Methods("POST")r.HandleFunc(prefix+"/plans/{planId}/{branch}/auto_load_context", handlers.AutoLoadContextHandler).Methods("POST")++ r.HandleFunc(prefix+"/plans/{planId}/{branch}/build_status", handlers.GetBuildStatusHandler).Methods("GET")}diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex 3d74a946..c51bbb5f 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -305,6 +305,11 @@ type RenamePlanRequest struct {Name string `json:"name"`}+type GetBuildStatusResponse struct {+ BuiltFiles map[string]bool `json:"builtFiles"`+ IsBuildingByPath map[string]bool `json:"isBuildingByPath"`+}+// Cloud requests and responsestype CreditsLogRequest struct {PageSize int `json:"pageSize"`