Skip to content

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

refactor: remove changes_tui in favor of git diff format

Dane Schneiderad4f1a6ea4f6
diff --git a/app/cli/changes_tui/actions.go b/app/cli/changes_tui/actions.go
deleted file mode 100644
index a21ed901..00000000
--- a/app/cli/changes_tui/actions.go
+++ /dev/null
@@ -1,212 +0,0 @@
-package changes_tui
-
-import (
- "fmt"
- "log"
- "plandex-cli/api"
- "plandex-cli/lib"
-
- shared "plandex-shared"
-
- "github.com/atotto/clipboard"
- "github.com/muesli/reflow/wrap"
-)
-
-func (m *changesUIModel) rejectFile() (*shared.CurrentPlanState, *shared.ApiError) {
- err := api.Client.RejectFile(lib.CurrentPlanId, lib.CurrentBranch, m.selectionInfo.currentPath)
-
- if err != nil {
- log.Printf("error rejecting file changes: %v", err)
- return nil, err
- }
-
- planState, err := api.Client.GetCurrentPlanState(lib.CurrentPlanId, lib.CurrentBranch)
-
- if err != nil {
- log.Printf("error getting current plan state: %v", err)
- return nil, err
- }
-
- return planState, nil
-}
-
-func (m *changesUIModel) copyCurrentChange() error {
- selectionInfo := m.selectionInfo
- if selectionInfo.currentRep == nil {
- return fmt.Errorf("no change is currently selected")
- }
-
- // Copy the 'New' content of the replacement to the clipboard
- if err := clipboard.WriteAll(selectionInfo.currentRep.New); err != nil {
- return fmt.Errorf("failed to copy to clipboard: %v", err)
- }
-
- m.didCopy = true
-
- return nil
-}
-
-func (m *changesUIModel) left() {
- if m.selectedFileIndex > 0 {
- m.selectedFileIndex--
- m.selectedReplacementIndex = 0
- }
- m.setSelectionInfo()
- m.updateMainView(true)
-}
-
-func (m *changesUIModel) right() {
- paths := m.currentPlan.PlanResult.SortedPaths
-
- if m.selectedFileIndex < len(paths)-1 {
- m.selectedFileIndex++
- m.selectedReplacementIndex = 0
- }
-
- m.setSelectionInfo()
- m.updateMainView(true)
-}
-
-func (m *changesUIModel) up() {
- if m.selectedReplacementIndex > 0 {
- // log.Println("up")
- m.selectedReplacementIndex--
- m.setSelectionInfo()
- m.updateMainView(true)
- }
-}
-
-func (m *changesUIModel) down() {
- var currentReplacements []*shared.Replacement
- if m.selectionInfo != nil {
- currentReplacements = m.selectionInfo.currentReplacements
- }
-
- max := len(currentReplacements) - 1
-
- // allow for selection of 'full file' option at bottom of replacement list in sidebar
- if m.currentPlan.PlanResult.NumPendingForPath(m.selectionInfo.currentPath) > 0 {
- max++
- }
-
- // allow for selection of 'new file' option at top of replacement list in sidebar
- if m.hasNewFile() {
- max++
- }
-
- if m.selectedReplacementIndex < max {
- // log.Println("down")
- m.selectedReplacementIndex++
- m.setSelectionInfo()
- m.updateMainView(true)
- }
-}
-
-func (m *changesUIModel) scrollUp() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.LineUp(1)
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.LineUp(1)
- } else if m.newScrollable() {
- m.changeNewViewport.LineUp(1)
- }
-}
-
-func (m *changesUIModel) scrollDown() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.LineDown(1)
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.LineDown(1)
- } else if m.newScrollable() {
- m.changeNewViewport.LineDown(1)
- }
-}
-
-func (m *changesUIModel) pageUp() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.ViewUp()
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.ViewUp()
- } else if m.newScrollable() {
- m.changeNewViewport.ViewUp()
- }
-}
-
-func (m *changesUIModel) pageDown() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.ViewDown()
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.ViewDown()
- } else if m.newScrollable() {
- m.changeNewViewport.ViewDown()
- }
-}
-
-func (m *changesUIModel) start() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.GotoTop()
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.GotoTop()
- } else if m.newScrollable() {
- m.changeNewViewport.GotoTop()
- }
-}
-
-func (m *changesUIModel) end() {
- if m.selectionInfo.currentRep == nil && m.fileScrollable() {
- m.fileViewport.GotoBottom()
- } else if m.selectedViewport == 0 && m.oldScrollable() {
- m.changeOldViewport.GotoBottom()
- } else if m.newScrollable() {
- m.changeNewViewport.GotoBottom()
- }
-}
-
-func (m *changesUIModel) switchView() {
- m.selectedViewport = 1 - m.selectedViewport
- m.updateMainView(false)
-}
-
-func (m *changesUIModel) windowResized(w, h int) {
- m.width = w
- m.height = h
- didInit := false
- if !m.ready {
- m.initViewports()
- m.ready = true
- didInit = true
- }
- m.updateMainView(didInit)
-}
-
-func (m *changesUIModel) updateMainView(scrollReplacement bool) {
- // log.Println("updateMainView")
-
- // var updateMsg types.ChangesUIViewportsUpdate
-
- if m.selectedNewFile() || m.selectedFullFile() {
- var updatedFile string
-
- if m.selectedNewFile() {
- updatedFile = m.selectionInfo.currentRes.Content
- } else {
- updatedFile = m.currentPlan.CurrentPlanFiles.Files[m.selectionInfo.currentPath]
- }
-
- wrapped := wrap.String(updatedFile, m.fileViewport.Width-2)
- m.fileViewport.SetContent(wrapped)
- } else {
- oldRes := m.getReplacementOldDisplay()
- m.changeOldViewport.SetContent(oldRes.oldDisplay)
- // log.Println("set old content")
- newContent, newContentDisplay := m.getReplacementNewDisplay(oldRes.prependContent, oldRes.appendContent)
- m.changeNewViewport.SetContent(newContentDisplay)
- // log.Println("set new content")
-
- if scrollReplacement {
- m.scrollReplacementIntoView(oldRes.old, newContent, oldRes.numLinesPrepended)
- }
- }
-
- m.updateViewportSizes()
-}
diff --git a/app/cli/changes_tui/main_viewport.go b/app/cli/changes_tui/main_viewport.go
deleted file mode 100644
index 2e551a99..00000000
--- a/app/cli/changes_tui/main_viewport.go
+++ /dev/null
@@ -1,162 +0,0 @@
-package changes_tui
-
-import (
- "fmt"
- "plandex-cli/term"
-
- "github.com/charmbracelet/lipgloss"
- "github.com/fatih/color"
-)
-
-func (m changesUIModel) renderMainView() string {
- // log.Println()
- // log.Println("renderMainView")
-
- mainViewHeader := m.renderMainViewHeader()
-
- if m.selectedNewFile() || m.selectedFullFile() {
- fileView := m.fileViewport.View()
-
- fileViews := []string{fileView}
-
- fileViews = append(fileViews, m.renderScrollFooter())
-
- fileContainer := lipgloss.JoinVertical(lipgloss.Left, fileViews...)
-
- fileContainerStyle := lipgloss.NewStyle().Width(m.fileViewport.Width)
- fileContainer = fileContainerStyle.Render(fileContainer)
-
- return lipgloss.JoinVertical(lipgloss.Left, mainViewHeader, fileContainer)
- } else {
- oldView := m.changeOldViewport.View()
- newView := m.changeNewViewport.View()
-
- oldViews := []string{oldView}
- newViews := []string{newView}
-
- if m.oldScrollable() && (m.selectedViewport == 0 || !m.newScrollable()) {
- oldViews = append(oldViews, m.renderScrollFooter())
- } else if m.newScrollable() && (m.selectedViewport == 1 || !m.oldScrollable()) {
- newViews = append(newViews, m.renderScrollFooter())
- }
-
- oldContainer := lipgloss.JoinVertical(lipgloss.Left, oldViews...)
- newContainer := lipgloss.JoinVertical(lipgloss.Left, newViews...)
-
- oldContainerStyle := lipgloss.NewStyle().Width(m.changeOldViewport.Width)
- oldContainer = oldContainerStyle.Render(oldContainer)
-
- newContainerStyle := lipgloss.NewStyle().
- BorderStyle(lipgloss.NormalBorder()).
- BorderLeft(true).
- BorderForeground(lipgloss.Color(borderColor)).
- Width(m.changeNewViewport.Width)
-
- newContainer = newContainerStyle.Render(newContainer)
-
- return lipgloss.JoinVertical(lipgloss.Left,
- mainViewHeader,
- lipgloss.JoinHorizontal(lipgloss.Top, oldContainer, newContainer),
- m.renderMainViewFooter(),
- )
- }
-
-}
-
-func (m changesUIModel) renderMainViewHeader() string {
- if m.selectionInfo == nil {
- return "\n"
- }
-
- sidebarWidth := lipgloss.Width(m.renderSidebar())
- style := lipgloss.NewStyle().
- Width(m.width - sidebarWidth).
- BorderStyle(lipgloss.NormalBorder()).
- BorderBottom(true).
- BorderForeground(borderColor)
-
- var header string
- if m.selectedFullFile() {
- numChanges := m.currentPlan.PlanResult.NumPendingForPath(m.selectionInfo.currentPath)
- if m.hasNewFile() {
- numChanges++
- }
-
- if numChanges > 0 {
- suffix := "s"
- if numChanges == 1 {
- suffix = ""
- }
- header = fmt.Sprintf(" βœ… Final state of %s (%d change%s)", m.selectionInfo.currentPath, numChanges, suffix)
- } else {
- header = fmt.Sprintf(" 🌟 New file: %s", m.selectionInfo.currentPath)
- }
- } else if m.selectedNewFile() {
- numChanges := m.currentPlan.PlanResult.NumPendingForPath(m.selectionInfo.currentPath)
- icon := "🌟"
- if numChanges > 1 {
- icon = "πŸ‘‰"
- }
-
- header = fmt.Sprintf(" %s New file: %s", icon, m.selectionInfo.currentPath)
-
- } else {
- header = " πŸ‘‰ " + m.selectionInfo.currentRep.GetSummary()
- }
-
- return style.Render(header)
-}
-
-func (m changesUIModel) renderMainViewFooter() string {
- if m.selectedFullFile() {
- return ""
- }
-
- sidebarWidth := lipgloss.Width(m.renderSidebar())
- style := lipgloss.NewStyle().
- Width(m.width - sidebarWidth).
- Inherit(topBorderStyle).
- Foreground(lipgloss.Color(helpTextColor))
- var footer string
- if m.didCopy {
- footer = color.New(color.Bold, term.ColorHiCyan).Sprint(` copied to clipboard`)
- } else {
- footer = ` (c)opy change to clipboard β€’ (r)eject file`
- }
- return style.Render(footer)
-}
-
-func (m changesUIModel) renderScrollFooter() string {
- if m.selectionInfo == nil {
- return ""
- }
-
- width, _ := m.getMainViewDims()
-
- if !m.selectedNewFile() && !m.selectedFullFile() {
- width = width / 2
- }
-
- var footer string
-
- if m.selectedNewFile() || m.selectedFullFile() {
- if m.fileScrollable() {
- footer = ` (j/k) scroll β€’ (d/u) page β€’ (g/G) start/end β€’ (r)eject file`
- } else {
- footer = ` (r)eject file`
- }
-
- } else {
- footer = ` (j/k) scroll`
- if m.oldScrollable() && m.newScrollable() {
- footer += ` β€’ (tab) switch view`
- }
- }
-
- style := lipgloss.NewStyle().
- Width(width).
- Inherit(topBorderStyle).
- Foreground(lipgloss.Color(helpTextColor))
-
- return style.Render(footer)
-}
diff --git a/app/cli/changes_tui/model.go b/app/cli/changes_tui/model.go
deleted file mode 100644
index c1d56283..00000000
--- a/app/cli/changes_tui/model.go
+++ /dev/null
@@ -1,159 +0,0 @@
-package changes_tui
-
-import (
- shared "plandex-shared"
-
- "github.com/charmbracelet/bubbles/help"
- bubbleKey "github.com/charmbracelet/bubbles/key"
- "github.com/charmbracelet/bubbles/spinner"
- "github.com/charmbracelet/bubbles/viewport"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/charmbracelet/lipgloss"
-)
-
-type changesUIModel struct {
- help help.Model
- keymap keymap
- selectedFileIndex int
- selectedReplacementIndex int
- selectedViewport int
- currentPlan *shared.CurrentPlanState
- changeOldViewport viewport.Model
- changeNewViewport viewport.Model
- fileViewport viewport.Model
- selectionInfo *selectionInfo
- ready bool
- width int
- height int
- shouldApplyAll bool
- shouldRejectAll bool
- didCopy bool
- isRejectingFile bool
- isConfirmingRejectFile bool
- rejectFileErr *shared.ApiError
- justRejectedFile bool
- spinner spinner.Model
-}
-
-type keymap = struct {
- up,
- down,
- left,
- right,
- scrollUp,
- scrollDown,
- pageUp,
- pageDown,
- start,
- end,
- switchView,
- reject,
- copy,
- applyAll,
- yes,
- no,
- quit bubbleKey.Binding
-}
-
-func (m changesUIModel) Init() tea.Cmd {
- return nil
-}
-
-func initialModel(currentPlan *shared.CurrentPlanState) *changesUIModel {
- s := spinner.New()
- s.Spinner = spinner.Points
- s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
-
- initialState := changesUIModel{
- currentPlan: currentPlan,
- selectedFileIndex: 0,
- selectedReplacementIndex: 0,
- help: help.New(),
- spinner: s,
- keymap: keymap{
- up: bubbleKey.NewBinding(
- bubbleKey.WithKeys("up"),
- bubbleKey.WithHelp("up", "prev change"),
- ),
-
- down: bubbleKey.NewBinding(
- 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"),
- ),
-
- scrollUp: bubbleKey.NewBinding(
- bubbleKey.WithKeys("k"),
- bubbleKey.WithHelp("k", "scroll up"),
- ),
-
- pageDown: bubbleKey.NewBinding(
- bubbleKey.WithKeys("d", "pageDown"),
- bubbleKey.WithHelp("d", "page down"),
- ),
-
- pageUp: bubbleKey.NewBinding(
- bubbleKey.WithKeys("u", "pageUp"),
- bubbleKey.WithHelp("u", "page up"),
- ),
-
- start: bubbleKey.NewBinding(
- bubbleKey.WithKeys("g", "home"),
- bubbleKey.WithHelp("g", "start"),
- ),
-
- end: bubbleKey.NewBinding(
- bubbleKey.WithKeys("G", "end"),
- bubbleKey.WithHelp("G", "end"),
- ),
-
- switchView: bubbleKey.NewBinding(
- bubbleKey.WithKeys("tab"),
- bubbleKey.WithHelp("tab", "switch view"),
- ),
-
- reject: bubbleKey.NewBinding(
- bubbleKey.WithKeys("r"),
- bubbleKey.WithHelp("r", "reject file"),
- ),
-
- copy: bubbleKey.NewBinding(
- bubbleKey.WithKeys("c"),
- bubbleKey.WithHelp("c", "copy change"),
- ),
-
- applyAll: bubbleKey.NewBinding(
- bubbleKey.WithKeys("ctrl+a"),
- bubbleKey.WithHelp("ctrl+a", "apply all changes"),
- ),
-
- yes: bubbleKey.NewBinding(
- bubbleKey.WithKeys("y"),
- bubbleKey.WithHelp("y", "yes"),
- ),
-
- no: bubbleKey.NewBinding(
- bubbleKey.WithKeys("n"),
- bubbleKey.WithHelp("n", "no"),
- ),
-
- quit: bubbleKey.NewBinding(
- bubbleKey.WithKeys("q", "ctrl+c"),
- bubbleKey.WithHelp("q", "quit"),
- ),
- },
- }
-
- return &initialState
-}
diff --git a/app/cli/changes_tui/path_tabs.go b/app/cli/changes_tui/path_tabs.go
deleted file mode 100644
index b1bb07a2..00000000
--- a/app/cli/changes_tui/path_tabs.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package changes_tui
-
-import (
- "plandex-cli/term"
- "strings"
-
- "github.com/charmbracelet/lipgloss"
- "github.com/fatih/color"
-)
-
-func (m changesUIModel) renderPathTabs() string {
- if m.selectionInfo == nil || m.width == 0 {
- return ""
- }
-
- var tabRows [][]string
-
- lineWidth := 0
- lineNum := 0
-
- paths := m.currentPlan.PlanResult.SortedPaths
-
- for i, path := range paths {
- selected := i == m.selectedFileIndex
-
- if len(path) > 40 {
- path = path[:20] + "β‹―" + path[len(path)-20:]
- }
-
- tab := " πŸ“„ " + path + " "
-
- pathColor := term.ColorHiGreen
- bgColor := color.BgGreen
-
- if selected {
- tab = color.New(color.Bold, bgColor, color.FgHiWhite).Sprint(tab)
- } else {
- tab = color.New(pathColor).Sprint(tab)
- }
-
- tabWidth := lipgloss.Width(tab)
-
- if tabWidth > m.width {
- return ""
- }
-
- if lineWidth+tabWidth > m.width {
- lineWidth = 0
- lineNum++
- }
-
- if len(tabRows) <= lineNum {
- tabRows = append(tabRows, []string{})
- }
-
- tabs := tabRows[lineNum]
- tabs = append(tabs, tab)
- tabRows[lineNum] = tabs
-
- lineWidth += tabWidth
- }
-
- resRows := make([]string, len(tabRows))
-
- for i, row := range tabRows {
- resRows[i] = strings.Join(row, "")
- }
-
- style := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).BorderForeground(lipgloss.Color(borderColor)).Width(m.width)
- tabs := strings.Join(resRows, "\n")
- return style.Render(tabs)
-}
diff --git a/app/cli/changes_tui/replace.go b/app/cli/changes_tui/replace.go
deleted file mode 100644
index 1d3d5a62..00000000
--- a/app/cli/changes_tui/replace.go
+++ /dev/null
@@ -1,175 +0,0 @@
-package changes_tui
-
-import (
- "plandex-cli/term"
- "strings"
-
- shared "plandex-shared"
-
- "github.com/fatih/color"
- "github.com/muesli/reflow/wrap"
-)
-
-const replacementPrependLines = 20
-const replacementAppendLines = 20
-
-type oldReplacementRes struct {
- old string
- oldDisplay string
- prependContent string
- numLinesPrepended int
- appendContent string
- numLinesAppended int
- entireFile bool
-}
-
-func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
-
- originalFile := m.selectionInfo.currentFilesBeforeReplacement.Files[m.selectionInfo.currentPath]
-
- var oldContent string
- if m.selectionInfo.currentRep.EntireFile {
- oldContent = originalFile
- } else {
- oldContent = m.selectionInfo.currentRep.Old
- }
-
- // log.Println(originalFile)
-
- oldContent = strings.ReplaceAll(oldContent, "\\`\\`\\`", "```")
- originalFile = strings.ReplaceAll(originalFile, "\\`\\`\\`", "```")
-
- // log.Printf("oldContent: %v", oldContent)
- // log.Printf("originalFile: %v", originalFile)
-
- if m.selectionInfo.currentRes.ReplaceWithLineNums {
- originalFile = shared.AddLineNums(originalFile)
- }
-
- // Convert originalFile to a slice of runes to properly handle multi-byte characters
- originalFileRunes := []rune(originalFile)
-
- // Convert oldContent to a slice of runes
- oldContentRunes := []rune(oldContent)
-
- // Find the index of oldContentRunes in originalFileRunes
- var fileIdx int
-
- if m.selectionInfo.currentRep.EntireFile {
- fileIdx = 0
- } else {
- fileIdx = shared.IndexRunes(originalFileRunes, oldContentRunes)
- if fileIdx == -1 {
- term.OutputErrorAndExit("Could not find replacement in original file")
- }
- }
-
- toPrepend := ""
- numLinesPrepended := 0
- for i := fileIdx - 1; i >= 0; i-- {
- s := string(originalFileRunes[i])
- // Prepend the string representation of the rune
- toPrepend = s + toPrepend
- if originalFileRunes[i] == '\n' {
- numLinesPrepended++
- if numLinesPrepended == replacementPrependLines {
- break
- }
- }
- }
-
- prependedToStart := strings.Index(originalFile, toPrepend) == 0
-
- toPrepend = strings.TrimLeft(toPrepend, "\n")
- if !prependedToStart {
- toPrepend = "…\n" + toPrepend
- }
-
- toPrepend = shared.RemoveLineNums(toPrepend)
-
- toAppend := ""
- numLinesAppended := 0
- // Convert originalFile to a slice of runes to properly handle multi-byte characters
- for i := fileIdx + len([]rune(oldContent)); i < len(originalFileRunes); i++ {
- s := string(originalFileRunes[i])
-
- if s == "\t" {
- s = " "
- }
- toAppend += s
- if originalFileRunes[i] == '\n' {
- numLinesAppended++
- if numLinesAppended == replacementAppendLines {
- break
- }
- }
- }
- appendedToEnd := strings.Index(originalFile, toAppend) == len(originalFile)-len(toAppend)
-
- toAppend = strings.TrimRight(toAppend, "\n")
-
- if !appendedToEnd {
- toAppend += "\n…"
- }
- toAppend = shared.RemoveLineNums(toAppend)
-
- wrapWidth := m.changeOldViewport.Width - 6
- toPrepend = wrap.String(toPrepend, wrapWidth)
- oldContent = shared.RemoveLineNums(oldContent)
- oldContent = wrap.String(oldContent, wrapWidth)
-
- // log.Println("toAppend", toAppend)
-
- toAppend = wrap.String(toAppend, wrapWidth)
-
- // log.Println("toAppend after wrap", toAppend)
-
- toPrependLines := strings.Split(toPrepend, "\n")
- for i, line := range toPrependLines {
- toPrependLines[i] = color.New(color.FgWhite).Sprint(line)
- }
- toPrepend = strings.Join(toPrependLines, "\n")
-
- oldContentLines := strings.Split(oldContent, "\n")
- for i, line := range oldContentLines {
- oldContentLines[i] = color.New(term.ColorHiRed).Sprint(line)
- }
- oldContent = strings.Join(oldContentLines, "\n")
-
- toAppendLines := strings.Split(toAppend, "\n")
- for i, line := range toAppendLines {
- toAppendLines[i] = color.New(color.FgWhite).Sprint(line)
- }
- toAppend = strings.Join(toAppendLines, "\n")
-
- oldDisplayContent := toPrepend + oldContent + toAppend
-
- numLinesPrepended = len(toPrependLines)
- numLinesAppended = len(toAppendLines)
-
- return oldReplacementRes{
- oldContent,
- oldDisplayContent,
- toPrepend,
- numLinesPrepended,
- toAppend,
- numLinesAppended,
- m.selectionInfo.currentRep.EntireFile,
- }
-}
-
-func (m changesUIModel) getReplacementNewDisplay(prependContent, appendContent string) (string, string) {
- newContent := m.selectionInfo.currentRep.New
-
- newContent = strings.ReplaceAll(newContent, "\\`\\`\\`", "```")
-
- newContent = wrap.String(newContent, m.changeNewViewport.Width-6)
-
- newContentLines := strings.Split(newContent, "\n")
- for i, line := range newContentLines {
- newContentLines[i] = color.New(term.ColorHiGreen).Sprint(line)
- }
- newContent = strings.Join(newContentLines, "\n")
-
- return newContent, prependContent + newContent + appendContent
-}
diff --git a/app/cli/changes_tui/run.go b/app/cli/changes_tui/run.go
deleted file mode 100644
index 106ccd1d..00000000
--- a/app/cli/changes_tui/run.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package changes_tui
-
-import (
- "fmt"
- "plandex-cli/lib"
- "plandex-cli/plan_exec"
- "plandex-cli/term"
- "plandex-cli/types"
-
- shared "plandex-shared"
-
- tea "github.com/charmbracelet/bubbletea"
-)
-
-var program *tea.Program
-
-func StartChangesUI(currentPlan *shared.CurrentPlanState) error {
- initial := initialModel(currentPlan)
-
- if len(initial.currentPlan.PlanResult.SortedPaths) == 0 {
- fmt.Println("πŸ€·β€β™‚οΈ No changes pending")
- return nil
- }
-
- program = tea.NewProgram(initial, tea.WithAltScreen())
-
- m, err := program.Run()
-
- if err != nil {
- return fmt.Errorf("error running changes UI: %v", err)
- }
-
- var mod *changesUIModel
- c, ok := m.(*changesUIModel)
-
- if ok {
- mod = c
- } else {
- c := m.(changesUIModel)
- mod = &c
- }
-
- if mod.shouldApplyAll {
- applyFlags := types.ApplyFlags{
- AutoConfirm: true,
- }
- lib.MustApplyPlan(lib.ApplyPlanParams{
- PlanId: lib.CurrentPlanId,
- Branch: lib.CurrentBranch,
- ApplyFlags: applyFlags,
- TellFlags: types.TellFlags{},
- OnExecFail: plan_exec.GetOnApplyExecFail(applyFlags, types.TellFlags{}),
- })
- }
-
- if mod.rejectFileErr != nil {
- fmt.Println()
- term.OutputErrorAndExit("Server error: " + mod.rejectFileErr.Msg)
- }
-
- if mod.justRejectedFile && len(mod.currentPlan.PlanResult.SortedPaths) == 0 {
- fmt.Println("🚫 All changes rejected")
- return nil
- }
-
- return nil
-}
diff --git a/app/cli/changes_tui/selection.go b/app/cli/changes_tui/selection.go
deleted file mode 100644
index f9e208fa..00000000
--- a/app/cli/changes_tui/selection.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package changes_tui
-
-import (
- "fmt"
- "log"
- "plandex-cli/term"
-
- shared "plandex-shared"
-)
-
-type selectionInfo struct {
- currentPath string
- currentRes *shared.PlanFileResult
- currentReplacements []*shared.Replacement
- currentRep *shared.Replacement
- currentFilesBeforeReplacement *shared.CurrentPlanFiles
-}
-
-func (m *changesUIModel) setSelectionInfo() {
- paths := m.currentPlan.PlanResult.SortedPaths
- currentPath := paths[m.selectedFileIndex]
-
- results := m.currentPlan.PlanResult.FileResultsByPath[currentPath]
-
- var currentRes *shared.PlanFileResult
- var currentRep *shared.Replacement
-
- var pathReplacements []*shared.Replacement
-
- for _, res := range results {
- pathReplacements = append(pathReplacements, res.Replacements...)
- }
-
- i := 0
-outer:
- for _, res := range results {
- if i == 0 && len(res.Replacements) == 0 && res.Content != "" {
- if m.selectedReplacementIndex == 0 {
- currentRes = res
- break outer
- } else {
- i++
- continue
- }
- }
-
- for _, rep := range res.Replacements {
- if i == m.selectedReplacementIndex {
- currentRes = res
- currentRep = rep
- break outer
- }
- i++
- }
- }
-
- var currentFilesBeforeReplacement *shared.CurrentPlanFiles
- var err error
-
- // log.Println("currentRep: ", currentRep)
-
- if currentRep == nil {
- currentFilesBeforeReplacement = m.currentPlan.CurrentPlanFiles
- } else {
- currentFilesBeforeReplacement, err = m.currentPlan.GetFilesBeforeReplacement(currentRep.Id)
- }
-
- // log.Println(spew.Sdump(currentFilesBeforeReplacement))
-
- if err != nil {
- err = fmt.Errorf("error getting current plan state: %v", err)
- log.Println(err)
- term.OutputErrorAndExit(err.Error())
- }
-
- m.selectionInfo = &selectionInfo{
- currentPath: currentPath,
- currentRes: currentRes,
- currentReplacements: pathReplacements,
- currentRep: currentRep,
- currentFilesBeforeReplacement: currentFilesBeforeReplacement,
- }
-}
diff --git a/app/cli/changes_tui/sidebar.go b/app/cli/changes_tui/sidebar.go
deleted file mode 100644
index 50ee6c93..00000000
--- a/app/cli/changes_tui/sidebar.go
+++ /dev/null
@@ -1,128 +0,0 @@
-package changes_tui
-
-import (
- "plandex-cli/term"
- "strings"
-
- shared "plandex-shared"
-
- "github.com/charmbracelet/lipgloss"
- "github.com/fatih/color"
-)
-
-func (m changesUIModel) renderSidebar() string {
- if m.selectionInfo == nil {
- return ""
- }
-
- currentRep := m.selectionInfo.currentRep
-
- var sb strings.Builder
- path := m.selectionInfo.currentPath
-
- results := m.currentPlan.PlanResult.FileResultsByPath[path]
- anyFailed := false
- anyApplied := false
- anyReplacements := false
-
- var replacements []*shared.Replacement
- var createdFile bool
-
- for i, result := range results {
- if m.hasNewFile() && i == 0 {
- createdFile = true
- selected := m.selectedNewFile()
- fgColor := term.ColorHiGreen
- bgColor := color.BgGreen
- icon := "🌟"
-
- var s string
- if selected {
- s += color.New(color.Bold, bgColor, color.FgHiWhite).Sprintf(" %s %d ", icon, 1)
- } else {
- s += color.New(fgColor).Sprintf(" %s %d ", icon, 1)
- }
-
- s += "\n"
- sb.WriteString(s)
- } else {
- replacements = append(replacements, result.Replacements...)
- }
- }
-
- // Change entries
- for i, rep := range replacements {
- num := i + 1
- if createdFile {
- num++
- }
- anyReplacements = true
- selected := currentRep != nil && rep.Id == currentRep.Id
- s := ""
-
- fgColor := term.ColorHiGreen
- bgColor := color.BgGreen
- if rep.Failed {
- fgColor = term.ColorHiRed
- bgColor = color.BgRed
- anyFailed = true
- } else if rep.RejectedAt != nil {
- fgColor = color.FgWhite
- bgColor = color.BgBlack
- }
-
- var icon string
- if rep.RejectedAt != nil {
- icon = "πŸ‘Ž"
- } else if rep.Failed {
- icon = "🚫"
- } else {
- icon = "πŸ“"
- }
-
- if !rep.Failed && rep.RejectedAt == nil {
- anyApplied = true
- }
-
- if selected {
- s += color.New(color.Bold, bgColor, color.FgHiWhite).Sprintf(" %s %d ", icon, num)
- } else {
- s += color.New(fgColor).Sprintf(" %s %d ", icon, num)
- }
-
- s += "\n"
-
- sb.WriteString(s)
- }
-
- if !anyReplacements {
- return ""
- }
-
- if anyApplied {
- fgColor := term.ColorHiGreen
- bgColor := color.BgGreen
- if anyFailed {
- fgColor = term.ColorHiRed
- bgColor = color.BgRed
- }
-
- if m.selectedFullFile() {
- sb.WriteString(color.New(color.Bold, bgColor, color.FgHiWhite).Sprint(" πŸ”€ β†’ "))
- } else {
- sb.WriteString(color.New(fgColor).Sprint(" πŸ”€ "))
- }
- }
-
- helpHeight := lipgloss.Height(m.renderHelp())
- tabsHeight := lipgloss.Height(m.renderPathTabs())
- sidebar := sb.String()
-
- style := lipgloss.NewStyle().
- Height(m.height - (helpHeight + tabsHeight)).
- BorderStyle(lipgloss.NormalBorder()).
- BorderRight(true).
- BorderForeground(borderColor)
-
- return style.Render(sidebar)
-}
diff --git a/app/cli/changes_tui/update.go b/app/cli/changes_tui/update.go
deleted file mode 100644
index 8c00fea8..00000000
--- a/app/cli/changes_tui/update.go
+++ /dev/null
@@ -1,206 +0,0 @@
-package changes_tui
-
-import (
- "plandex-cli/types"
- "time"
-
- shared "plandex-shared"
-
- bubbleKey "github.com/charmbracelet/bubbles/key"
- "github.com/charmbracelet/bubbles/spinner"
- tea "github.com/charmbracelet/bubbletea"
-)
-
-type toggleDidCopyOffMsg struct{}
-type finishedRejectFile struct {
- planState *shared.CurrentPlanState
- err *shared.ApiError
-}
-
-func (m changesUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
- // log.Println("msg:", msg)
-
- if m.selectionInfo == nil {
- m.setSelectionInfo()
- }
-
- switch msg := msg.(type) {
-
- case tea.WindowSizeMsg:
- m.windowResized(msg.Width, msg.Height)
-
- case types.ChangesUIViewportsUpdate:
- m.updateViewportSizes()
- if msg.ScrollReplacement != nil {
- m.scrollReplacementIntoView(msg.ScrollReplacement.OldContent, msg.ScrollReplacement.NewContent, msg.ScrollReplacement.NumLinesPrepended)
- }
-
- case spinner.TickMsg:
- if m.isRejectingFile {
- spinnerModel, cmd := m.spinner.Update(msg)
- m.spinner = spinnerModel
- return m, cmd
- }
-
- case toggleDidCopyOffMsg:
- m.didCopy = false
-
- case finishedRejectFile:
- m.justRejectedFile = true
-
- if msg.err != nil {
- m.rejectFileErr = msg.err
- return m, tea.Quit
- }
-
- m.currentPlan = msg.planState
-
- if len(msg.planState.PlanResult.SortedPaths) == 0 {
- return m, tea.Quit
- }
-
- m.isRejectingFile = false
- m.justRejectedFile = false
- m.selectedFileIndex = 0
- m.selectedReplacementIndex = 0
- m.setSelectionInfo()
- m.updateMainView(true)
-
- case tea.KeyMsg:
- if m.isConfirmingRejectFile {
- if !bubbleKey.Matches(msg, m.keymap.yes) && !bubbleKey.Matches(msg, m.keymap.no) &&
- !bubbleKey.Matches(msg, m.keymap.quit) {
- return m, nil
- }
- }
-
- if m.isRejectingFile {
- if !bubbleKey.Matches(msg, m.keymap.quit) {
- return m, nil
- }
- }
-
- switch {
-
- case bubbleKey.Matches(msg, m.keymap.left):
- m.left()
-
- case bubbleKey.Matches(msg, m.keymap.right):
- m.right()
-
- case bubbleKey.Matches(msg, m.keymap.up):
- m.up()
-
- case bubbleKey.Matches(msg, m.keymap.down):
- m.down()
-
- case bubbleKey.Matches(msg, m.keymap.scrollDown):
- m.scrollDown()
-
- case bubbleKey.Matches(msg, m.keymap.scrollUp):
- m.scrollUp()
-
- case bubbleKey.Matches(msg, m.keymap.pageDown):
- m.pageDown()
-
- case bubbleKey.Matches(msg, m.keymap.pageUp):
- m.pageUp()
-
- case bubbleKey.Matches(msg, m.keymap.start):
- m.start()
-
- case bubbleKey.Matches(msg, m.keymap.end):
- m.end()
-
- case bubbleKey.Matches(msg, m.keymap.switchView):
- m.switchView()
-
- case bubbleKey.Matches(msg, m.keymap.reject):
- m.isConfirmingRejectFile = true
-
- case bubbleKey.Matches(msg, m.keymap.yes):
- m.isRejectingFile = true
- m.isConfirmingRejectFile = false
- started := time.Now()
- go func() {
- planState, err := m.rejectFile()
-
- // If the rejectFile call took less than 500ms, wait a bit so the spinner
- // doesn't flash jarringly.
- elapsed := time.Since(started)
- if elapsed < 500*time.Millisecond {
- time.Sleep((500 * time.Millisecond) - elapsed)
- }
-
- if err != nil {
- program.Send(finishedRejectFile{err: err})
- return
- }
- program.Send(finishedRejectFile{planState: planState})
- }()
- return m, m.spinner.Tick
-
- case bubbleKey.Matches(msg, m.keymap.no):
- m.isConfirmingRejectFile = false
-
- case bubbleKey.Matches(msg, m.keymap.applyAll):
- m.shouldApplyAll = true
- return m, tea.Quit
-
- case bubbleKey.Matches(msg, m.keymap.copy):
- m.copyCurrentChange()
- time.AfterFunc(1*time.Second, func() {
- program.Send(toggleDidCopyOffMsg{})
- })
-
- case bubbleKey.Matches(msg, m.keymap.quit):
- return m, tea.Quit
-
- default:
- // handle escape sequences sometimes sent by arrow keys
- m.resolveEscapeSequence(msg.String())
- }
- }
-
- return m, nil
-}
-
-var escReceivedAt time.Time
-var escSeq string
-
-func (m *changesUIModel) resolveEscapeSequence(val string) {
- if val == "esc" || val == "alt+[" {
- escReceivedAt = time.Now()
- go func() {
- time.Sleep(51 * time.Millisecond)
- escReceivedAt = time.Time{}
- escSeq = ""
- }()
- }
-
- if !escReceivedAt.IsZero() {
- elapsed := time.Since(escReceivedAt)
-
- if elapsed < 50*time.Millisecond {
- escSeq += val
-
- if escSeq == "esc[A" || escSeq == "alt+[A" {
- m.up()
- escReceivedAt = time.Time{}
- escSeq = ""
- } else if escSeq == "esc[B" || escSeq == "alt+[B" {
- 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/app/cli/changes_tui/view.go b/app/cli/changes_tui/view.go
deleted file mode 100644
index 49e6eb75..00000000
--- a/app/cli/changes_tui/view.go
+++ /dev/null
@@ -1,245 +0,0 @@
-package changes_tui
-
-import (
- "plandex-cli/term"
- "strings"
-
- "github.com/charmbracelet/bubbles/viewport"
- "github.com/charmbracelet/lipgloss"
- "github.com/fatih/color"
-)
-
-var borderColor = lipgloss.Color("#444")
-var helpTextColor = lipgloss.Color("#ddd")
-var topBorderStyle = lipgloss.NewStyle().
- BorderStyle(lipgloss.NormalBorder()).
- BorderTop(true).
- BorderForeground(borderColor)
-
-func (m changesUIModel) View() string {
- if m.isConfirmingRejectFile {
- return m.renderConfirmRejectFile()
- }
-
- if m.isRejectingFile {
- return m.renderIsRejectingFile()
- }
-
- help := m.renderHelp()
-
- tabs := m.renderPathTabs()
-
- sidebar := m.renderSidebar()
-
- mainView := m.renderMainView()
-
- layout := lipgloss.JoinHorizontal(lipgloss.Top, sidebar, mainView)
-
- view := lipgloss.JoinVertical(lipgloss.Left,
- tabs,
- layout,
- help,
- )
-
- return view
-}
-
-func (m changesUIModel) getMainViewDims() (int, int) {
- tabsHeight := lipgloss.Height(m.renderPathTabs())
- helpHeight := lipgloss.Height(m.renderHelp())
- sidebarWidth := lipgloss.Width(m.renderSidebar())
- mainViewHeaderHeight := lipgloss.Height(m.renderMainViewHeader())
- mainViewFooterHeight := lipgloss.Height(m.renderMainViewFooter())
-
- mainViewWidth := m.width - sidebarWidth
- mainViewHeight := m.height - (helpHeight + tabsHeight)
-
- if m.selectedNewFile() || m.selectedFullFile() {
- mainViewHeight -= mainViewHeaderHeight
- } else {
- mainViewHeight -= (mainViewHeaderHeight + mainViewFooterHeight)
- }
-
- return mainViewWidth, mainViewHeight
-}
-
-func (m *changesUIModel) initViewports() {
- mainViewWidth, mainViewHeight := m.getMainViewDims()
- m.changeOldViewport = viewport.New(mainViewWidth/2, mainViewHeight)
- m.changeOldViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
- m.changeNewViewport = viewport.New(mainViewWidth/2, mainViewHeight)
- m.changeNewViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
- m.fileViewport = viewport.New(mainViewWidth, mainViewHeight)
- m.fileViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
-}
-
-func (m *changesUIModel) updateViewportSizes() {
- // log.Println()
- // log.Println()
- // log.Println("updateViewportSizes")
-
- mainViewWidth, mainViewHeight := m.getMainViewDims()
-
- if m.selectedNewFile() || m.selectedFullFile() {
- fileViewHeight := mainViewHeight
-
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- fileViewHeight -= footerHeight
-
- m.fileViewport.Width = mainViewWidth
- m.fileViewport.Height = fileViewHeight
-
- } else {
- // log.Println("mainViewHeight", mainViewHeight)
-
- mainViewHeight := mainViewHeight
- oldViewHeight := mainViewHeight
- newViewHeight := mainViewHeight
- // set widths and reset heights
- // log.Println("resetting widths and heights")
- m.resetViewportDims()
-
- // log.Println("oldScrollable", m.oldScrollable())
- // log.Println("newScrollable", m.newScrollable())
- // log.Println("selectedViewport", m.selectedViewport)
-
- if m.oldScrollable() && (m.selectedViewport == 0 || !m.newScrollable()) {
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- oldViewHeight -= footerHeight
- } else if m.newScrollable() && (m.selectedViewport == 1 || !m.oldScrollable()) {
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- newViewHeight -= footerHeight
- }
-
- // log.Println("oldViewHeight", oldViewHeight)
- // log.Println("newViewHeight", newViewHeight)
-
- // set updated heights
- m.changeOldViewport.Height = oldViewHeight
- m.changeNewViewport.Height = newViewHeight
-
- // log.Println("updated heights")
- }
-}
-
-func (m *changesUIModel) resetViewportDims() {
- mainViewWidth, mainViewHeight := m.getMainViewDims()
- m.fileViewport.Width = mainViewWidth
- m.fileViewport.Height = mainViewHeight
- m.changeOldViewport.Width = mainViewWidth / 2
- m.changeOldViewport.Height = mainViewHeight
- m.changeNewViewport.Width = mainViewWidth / 2
- m.changeNewViewport.Height = mainViewHeight
-}
-
-func (m changesUIModel) renderHelp() string {
- help := " "
-
- if len(m.currentPlan.PlanResult.SortedPaths) > 1 {
- help += "(←/β†’) select file β€’ "
- }
-
- if m.selectionInfo != nil {
- help += "(↑/↓) select change β€’ "
- }
-
- help += "(ctrl+a) apply all changes β€’ (q)uit"
- style := lipgloss.NewStyle().Width(m.width).Inherit(topBorderStyle).Foreground(lipgloss.Color(helpTextColor))
- return style.Render(help)
-}
-
-func (m changesUIModel) oldScrollable() bool {
- // log.Println("oldScrollable")
- // log.Println("TotalLineCount", m.changeOldViewport.TotalLineCount())
- // log.Println("VisibleLineCount", m.changeOldViewport.VisibleLineCount())
-
- return m.changeOldViewport.TotalLineCount() > m.changeOldViewport.VisibleLineCount()
-}
-
-func (m changesUIModel) newScrollable() bool {
- // log.Println("newScrollable")
- // log.Println("TotalLineCount", m.changeNewViewport.TotalLineCount())
- // log.Println("VisibleLineCount", m.changeNewViewport.VisibleLineCount())
-
- return m.changeNewViewport.TotalLineCount() > m.changeNewViewport.VisibleLineCount()
-}
-
-func (m changesUIModel) fileScrollable() bool {
- return m.fileViewport.TotalLineCount() > m.fileViewport.VisibleLineCount()
-}
-
-func (m changesUIModel) hasNewFile() bool {
- firstRes := m.currentPlan.PlanResult.FileResultsByPath[m.selectionInfo.currentPath][0]
- return len(firstRes.Replacements) == 0 && firstRes.Content != ""
-}
-
-func (m changesUIModel) selectedNewFile() bool {
- return m.selectionInfo != nil &&
- m.hasNewFile() &&
- m.selectedReplacementIndex == 0 &&
- m.selectionInfo.currentRes != nil &&
- len(m.selectionInfo.currentRes.Replacements) == 0 &&
- m.selectionInfo.currentRes.Content != ""
-}
-
-func (m changesUIModel) selectedFullFile() bool {
- return !m.selectedNewFile() && m.selectionInfo != nil && m.selectionInfo.currentRep == nil
-}
-
-func (m *changesUIModel) scrollReplacementIntoView(oldContent, newContent string, numLinesPrepended int) {
- scrollView := func(content string, view *viewport.Model) {
- view.GotoTop()
-
- if numLinesPrepended <= 2 {
- return
- }
-
- totalLines := view.TotalLineCount()
- visibleLines := view.VisibleLineCount()
- contentLines := len(strings.Split(content, "\n"))
-
- if contentLines >= (visibleLines - 2) {
- view.LineDown(numLinesPrepended - 2)
- } else {
- toScroll := getSnippetScrollPosition(totalLines, visibleLines, numLinesPrepended, contentLines)
- view.LineDown(toScroll)
- }
- }
-
- if m.oldScrollable() {
- scrollView(oldContent, &m.changeOldViewport)
- }
- if m.newScrollable() {
- scrollView(newContent, &m.changeNewViewport)
- }
-}
-
-func (m changesUIModel) renderConfirmRejectFile() string {
- style := lipgloss.NewStyle().Padding(1).BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color(borderColor)).Width(m.width - 2).Height(m.height - 2)
-
- prompt := color.New(color.Bold).Sprintf("🧐 Are you sure you want to reject changes to ") +
- color.New(color.Bold, term.ColorHiMagenta).Sprint(m.selectionInfo.currentPath) + "?\n\n" +
- color.New(term.ColorHiCyan, color.Bold).Sprintf("(y)es | (n)o")
-
- return style.Render(prompt)
-}
-
-func (m changesUIModel) renderIsRejectingFile() string {
- style := lipgloss.NewStyle().Padding(1).BorderStyle(lipgloss.NormalBorder()).BorderForeground(lipgloss.Color(borderColor)).Width(m.width - 2).Height(m.height - 2)
-
- return style.Render(m.spinner.View())
-}
-
-func getSnippetScrollPosition(totalLines, viewportHeight, snippetLineIndex, snippetHeight int) int {
- snippetMiddleLine := snippetLineIndex + snippetHeight/2
- viewportMiddleLine := viewportHeight / 2
-
- // Initial target scroll position
- scrollPosition := snippetMiddleLine - viewportMiddleLine
-
- // Adjust for bounds
- scrollPosition = max(scrollPosition, 0) // Adjust for top bound
- scrollPosition = min(scrollPosition, totalLines-viewportHeight) // Adjust for bottom bound
-
- return scrollPosition
-}
diff --git a/app/cli/cmd/changes.go b/app/cli/cmd/changes.go
deleted file mode 100644
index d18ff8c8..00000000
--- a/app/cli/cmd/changes.go
+++ /dev/null
@@ -1,122 +0,0 @@
-package cmd
-
-import (
- "fmt"
- "plandex-cli/api"
- "plandex-cli/auth"
- "plandex-cli/changes_tui"
- "plandex-cli/lib"
- "plandex-cli/plan_exec"
- "plandex-cli/term"
- "plandex-cli/types"
-
- shared "plandex-shared"
-
- "github.com/spf13/cobra"
-)
-
-func init() {
- RootCmd.AddCommand(changesCmd)
-}
-
-var changesCmd = &cobra.Command{
- Use: "changes",
- Short: "View, copy, or manage changes for the current plan",
- Run: changes,
-}
-
-func changes(cmd *cobra.Command, args []string) {
- auth.MustResolveAuthWithOrg()
- lib.MustResolveProject()
-
- term.StartSpinner("")
-
- currentPlanState, apiErr := api.Client.GetCurrentPlanState(lib.CurrentPlanId, lib.CurrentBranch)
-
- if apiErr != nil {
- term.StopSpinner()
- term.OutputErrorAndExit("Error getting current plan state: %s", apiErr.Msg)
- }
-
- // log.Println(spew.Sdump(currentPlanState))
-
- for currentPlanState.HasPendingBuilds() {
- plansRunningRes, apiErr := api.Client.ListPlansRunning([]string{lib.CurrentProjectId}, false)
-
- if apiErr != nil {
- term.StopSpinner()
- term.OutputErrorAndExit("Error getting running plans: %s", apiErr.Msg)
- }
-
- viewIncomplete := false
-
- for _, b := range plansRunningRes.Branches {
- if b.PlanId == lib.CurrentPlanId && b.Name == lib.CurrentBranch {
- fmt.Println("This plan is currently active.")
-
- res, err := term.ConfirmYesNo("View potentially incomplete changes anyway?")
-
- if err != nil {
- term.OutputErrorAndExit("Error getting confirmation user input: %v", err)
- }
-
- if res {
- viewIncomplete = true
- break
- } else {
- fmt.Println()
- term.PrintCmds("", "ps", "connect")
- return
- }
- }
- }
-
- term.StopSpinner()
-
- if !viewIncomplete {
- fmt.Println("This plan has unbuilt changes. Building now.")
-
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyApiKeys()
- }
-
- didBuild, err := plan_exec.Build(plan_exec.ExecParams{
- CurrentPlanId: lib.CurrentPlanId,
- CurrentBranch: lib.CurrentBranch,
- ApiKeys: apiKeys,
- CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool, error) {
- return lib.CheckOutdatedContextWithOutput(true, false, maybeContexts)
- },
- }, types.BuildFlags{})
-
- if err != nil {
- term.OutputErrorAndExit("Error building plan: %v\n", err)
- }
-
- if !didBuild {
- fmt.Println("Build canceled")
- fmt.Println()
- term.PrintCmds("", "build", "log", "rewind")
- return
- }
-
- term.ResumeSpinner()
- currentPlanState, apiErr = api.Client.GetCurrentPlanState(lib.CurrentPlanId, lib.CurrentBranch)
-
- if apiErr != nil {
- term.StopSpinner()
- term.OutputErrorAndExit("Error getting current plan state: %s", apiErr.Msg)
- }
- }
- }
-
- term.StopSpinner()
-
- err := changes_tui.StartChangesUI(currentPlanState)
-
- if err != nil {
- term.OutputErrorAndExit("Error starting changes UI: %v\n", err)
- }
-
-}