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
fixes for apply/changes tui with new files
Dane Schneider98eace9f3d1b
diff --git a/cli/changes_tui/main_viewport.go b/cli/changes_tui/main_viewport.goindex 9c9d5e34..e5fea23c 100644--- a/cli/changes_tui/main_viewport.go+++ b/cli/changes_tui/main_viewport.go@@ -75,11 +75,16 @@ func (m changesUIModel) renderMainViewHeader() string {var header stringif m.selectedFullFile() {numChanges := m.selectionInfo.currentPlanBeforeReplacement.NumPendingForPath(m.selectionInfo.currentPath)- suffix := "s"- if numChanges == 1 {- suffix = ""++ if numChanges > 0 {+ suffix := "s"+ if numChanges == 1 {+ suffix = ""+ }+ header = fmt.Sprintf(" ✅ Final state of %s including %d change%s", m.selectionInfo.currentPath, numChanges, suffix)+ } else {+ header = fmt.Sprintf(" ✅ New file: %s", m.selectionInfo.currentPath)}- header = fmt.Sprintf(" ✅ "+"Final state of file including %d change%s", numChanges, suffix)} else {header = " 👉 " + m.selectionInfo.currentRep.Summary}diff --git a/cli/changes_tui/model.go b/cli/changes_tui/model.goindex f9883ae4..dc2490f0 100644--- a/cli/changes_tui/model.go+++ b/cli/changes_tui/model.go@@ -74,7 +74,14 @@ func initialModel() *changesUIModel {bubbleKey.WithKeys("down"),bubbleKey.WithHelp("down", "next change"),),-+ left: bubbleKey.NewBinding(+ bubbleKey.WithKeys("left"),+ bubbleKey.WithHelp("left", "prev file"),+ ),+ right: bubbleKey.NewBinding(+ bubbleKey.WithKeys("right"),+ bubbleKey.WithHelp("right", "next file"),+ ),scrollDown: bubbleKey.NewBinding(bubbleKey.WithKeys("j"),bubbleKey.WithHelp("j", "scroll down"),diff --git a/cli/changes_tui/sidebar.go b/cli/changes_tui/sidebar.goindex c0272325..13d68f20 100644--- a/cli/changes_tui/sidebar.go+++ b/cli/changes_tui/sidebar.go@@ -8,8 +8,6 @@ import ()func (m changesUIModel) renderSidebar() string {- paths := m.currentPlan.SortedPaths-if m.selectionInfo == nil {return ""}@@ -17,60 +15,62 @@ func (m changesUIModel) renderSidebar() string {currentRep := m.selectionInfo.currentRepvar sb strings.Builder+ path := m.selectionInfo.currentPath++ results := m.currentPlan.PlanResByPath[path]+ anyFailed := false+ anyApplied := false+ anyReplacements := false++ // Change entries+ for i, result := range results {+ for j, rep := range result.Replacements {+ anyReplacements = true+ flatIndex := i*len(result.Replacements) + j+ selected := currentRep != nil && rep.Id == currentRep.Id+ s := ""++ fgColor := color.FgHiGreen+ bgColor := color.BgGreen+ if rep.Failed {+ fgColor = color.FgHiRed+ bgColor = color.BgRed+ anyFailed = true+ } else if rep.RejectedAt != "" {+ fgColor = color.FgWhite+ bgColor = color.BgBlack+ }- for _, path := range paths {- results := m.currentPlan.PlanResByPath[path]- anyFailed := false- anyApplied := false-- // Change entries- for i, result := range results {- for j, rep := range result.Replacements {- flatIndex := i*len(result.Replacements) + j- selected := currentRep != nil && rep.Id == currentRep.Id- s := ""-- fgColor := color.FgHiGreen- bgColor := color.BgGreen- if rep.Failed {- fgColor = color.FgHiRed- bgColor = color.BgRed- anyFailed = true- } else if rep.RejectedAt != "" {- fgColor = color.FgWhite- bgColor = color.BgBlack- }-- var icon string- if rep.RejectedAt != "" {- icon = "👎"- } else if rep.Failed {- icon = "🚫"- } else {- icon = "📝"- }-- if !rep.Failed && rep.RejectedAt == "" {- anyApplied = true- }-- if selected {- s += color.New(color.Bold, bgColor, color.FgHiWhite).Sprintf(" > %s %d ", icon, flatIndex+1)- } else {- s += color.New(fgColor).Sprintf(" - %s %d ", icon, flatIndex+1)- }-- s += "\n"-- sb.WriteString(s)+ var icon string+ if rep.RejectedAt != "" {+ icon = "👎"+ } else if rep.Failed {+ icon = "🚫"+ } else {+ icon = "📝"}- }+ if !rep.Failed && rep.RejectedAt == "" {+ anyApplied = true+ }++ if selected {+ s += color.New(color.Bold, bgColor, color.FgHiWhite).Sprintf(" > %s %d ", icon, flatIndex+1)+ } else {+ s += color.New(fgColor).Sprintf(" - %s %d ", icon, flatIndex+1)+ }- if !anyApplied {- continue+ s += "\n"++ sb.WriteString(s)}+ }++ if !anyReplacements {+ return ""+ }+ if anyApplied {fgColor := color.FgHiGreenbgColor := color.BgGreenif anyFailed {diff --git a/cli/changes_tui/update.go b/cli/changes_tui/update.goindex 556fb38e..0fc5e8e5 100644--- a/cli/changes_tui/update.go+++ b/cli/changes_tui/update.go@@ -1,6 +1,7 @@package changes_tuiimport (+ "log""time"bubbleKey "github.com/charmbracelet/bubbles/key"@@ -95,6 +96,8 @@ func (m *changesUIModel) resolveEscapeSequence(val string) {if elapsed < 50*time.Millisecond {escSeq += val+ log.Println("escSeq:", escSeq)+if escSeq == "esc[A" || escSeq == "alt+[A" {m.up()escReceivedAt = time.Time{}@@ -103,6 +106,14 @@ func (m *changesUIModel) resolveEscapeSequence(val string) {m.down()escReceivedAt = time.Time{}escSeq = ""+ } else if escSeq == "esc[C" || escSeq == "alt+[C" {+ m.right()+ escReceivedAt = time.Time{}+ escSeq = ""+ } else if escSeq == "esc[D" || escSeq == "alt+[D" {+ m.left()+ escReceivedAt = time.Time{}+ escSeq = ""}}}diff --git a/cli/changes_tui/view.go b/cli/changes_tui/view.goindex 692d8a5c..ff6b61cf 100644--- a/cli/changes_tui/view.go+++ b/cli/changes_tui/view.go@@ -98,7 +98,17 @@ func (m *changesUIModel) updateViewportSizes() {}func (m changesUIModel) renderHelp() string {- help := ` (↑/↓) select change • (ctrl+a) apply pending • (ctrl+d) drop all • (q)uit`+ help := " "++ if len(m.currentPlan.SortedPaths) > 1 {+ help += "(←/→) select file • "+ }++ if m.renderSidebar() != "" {+ help += "(↑/↓) select change • "+ }++ help += "(ctrl+a) apply pending • (ctrl+d) drop all • (q)uit"style := lipgloss.NewStyle().Width(m.width).Inherit(topBorderStyle).Foreground(lipgloss.Color(helpTextColor))return style.Render(help)}diff --git a/cli/lib/apply.go b/cli/lib/apply.goindex 159db5d1..3a40e034 100644--- a/cli/lib/apply.go+++ b/cli/lib/apply.go@@ -45,6 +45,11 @@ func ApplyPlanWithOutput(name string, autoConfirm bool) error {currentPlanFiles := res.CurrentPlanFilesplanResByPath := res.PlanResByPath+ if len(currentPlanFiles.Files) == 0 {+ fmt.Println("🤷♂️ No changes to apply")+ return nil+ }+aborted := false// check if any files have been modified since the plan result was generateddiff --git a/cli/lib/current_plan.go b/cli/lib/current_plan.goindex c8475b46..8555a369 100644--- a/cli/lib/current_plan.go+++ b/cli/lib/current_plan.go@@ -192,7 +192,6 @@ func GetPlanResultsInfo() (*types.PlanResultsInfo, error) {if !resDirExists {return &types.PlanResultsInfo{PlanResByPath: resByPath,- SortedPaths: paths,ReplacementsByPath: replacementsByPath,}, nil}diff --git a/server/model/prompts/create.go b/server/model/prompts/create.goindex 0f5e937a..421cd8e8 100644--- a/server/model/prompts/create.go+++ b/server/model/prompts/create.go@@ -37,7 +37,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextIf code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.- Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'.+ Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. Don't ask the user to create new files or directories--you must do that yourself.For code in markdown blocks, always include the language name after the opening triple backticks.@@ -53,6 +53,8 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextFor changes that are larger or more complex, only include one change per response.+ In general, don't ask the user to take an action that you are able to do. You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. As long as you have enough information to create them correctly, you should create them all.+At the end of a plan, you can suggest additional iterations to make the plan better. You can also ask the user to load more files or information into context if it would help you make a better plan.Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context. For example, if you are working on a plan that has been broken up into subtasks, and you've reached the point of implementing a particular subtask, first consider whether the subtask is still necessary looking at the files in context. If it has already been implemented or is no longer necessary, say so, revise the plan if needed, and move on. Otherwise, implement the subtask.diff --git a/shared/plan_result.go b/shared/plan_result.goindex 65f88dd2..71f19f65 100644--- a/shared/plan_result.go+++ b/shared/plan_result.go@@ -25,7 +25,7 @@ func (res *PlanResult) NumPendingReplacements() int {}func (res *PlanResult) IsPending() bool {- return res.AppliedAt == "" && res.RejectedAt == "" && res.NumPendingReplacements() > 0+ return res.AppliedAt == "" && res.RejectedAt == "" && (res.Content != "" || res.NumPendingReplacements() > 0)}func (p PlanResultsByPath) SetApplied(ts string) {@@ -54,6 +54,7 @@ func (p PlanResultsByPath) SetRejected(ts string) int {}}}+ return numRejected}func (p PlanResultsByPath) NumPending() int {