Skip to content

Commit

Permalink
- Fixes for changes TUI replacement view
Browse files Browse the repository at this point in the history
- Fixes for changes TUI text encoding issue
- Fixes context loading
- 'plandex rm' can now remove a directory from context
- 'plandex apply' fixes to avoid possible conflicts
- 'plandex apply' ask user whether to commit changes
- Context update fixes
- Command suggestions can be disabled with PLANDEX_DISABLE_SUGGESTIONS environment variable

- Lots of build fixes and prompt improvements
- Sanity check limit on number of auto-continue responses
- SMTP email option
- server release script
- various other fixes and improvements
  • Loading branch information
danenania committed Mar 23, 2024
1 parent edde9e5 commit 6536be9
Show file tree
Hide file tree
Showing 42 changed files with 536 additions and 255 deletions.
24 changes: 19 additions & 5 deletions app/cli/changes_tui/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
oldContent := m.selectionInfo.currentRep.Old
originalFile := m.selectionInfo.currentFilesBeforeReplacement.Files[m.selectionInfo.currentPath]

// log.Println(originalFile)

oldContent = strings.ReplaceAll(oldContent, "\\`\\`\\`", "```")
originalFile = strings.ReplaceAll(originalFile, "\\`\\`\\`", "```")

Expand All @@ -35,18 +37,23 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
panic("old content not found in full file") // should never happen
}

// Convert originalFile to a slice of runes to properly handle multi-byte characters
originalFileRunes := []rune(originalFile)

toPrepend := ""
numLinesPrepended := 0
for i := fileIdx - 1; i >= 0; i-- {
s := string(originalFile[i])
s := string(originalFileRunes[i])
// Prepend the string representation of the rune
toPrepend = s + toPrepend
if originalFile[i] == '\n' {
if originalFileRunes[i] == '\n' {
numLinesPrepended++
if numLinesPrepended == replacementPrependLines {
break
}
}
}

prependedToStart := strings.Index(originalFile, toPrepend) == 0

toPrepend = strings.TrimLeft(toPrepend, "\n")
Expand All @@ -56,13 +63,15 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {

toAppend := ""
numLinesAppended := 0
for i := fileIdx + len(oldContent); i < len(originalFile); i++ {
s := string(originalFile[i])
// 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 originalFile[i] == '\n' {
if originalFileRunes[i] == '\n' {
numLinesAppended++
if numLinesAppended == replacementAppendLines {
break
Expand All @@ -80,8 +89,13 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
wrapWidth := m.changeOldViewport.Width - 6
toPrepend = wrap.String(toPrepend, wrapWidth)
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)
Expand Down
5 changes: 5 additions & 0 deletions app/cli/changes_tui/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ outer:
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)
Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func branches(cmd *cobra.Command, args []string) {
for i, b := range branches {
num := strconv.Itoa(i + 1)
if b.Name == lib.CurrentBranch {
num = color.New(color.Bold, color.FgGreen).Sprint(num)
num = color.New(color.Bold, term.ColorHiGreen).Sprint(num)
}

var name string
if b.Name == lib.CurrentBranch {
name = color.New(color.Bold, color.FgGreen).Sprint(b.Name) + " 👈"
name = color.New(color.Bold, term.ColorHiGreen).Sprint(b.Name) + " 👈"
} else {
name = b.Name
}
Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func build(cmd *cobra.Command, args []string) {
didBuild, err := plan_exec.Build(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
},
}, buildBg)

Expand Down
2 changes: 1 addition & 1 deletion app/cli/cmd/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cd(cmd *cobra.Command, args []string) {
// give the SetProjectPlan request some time to be sent before exiting
time.Sleep(50 * time.Millisecond)

fmt.Println("✅ Changed current plan to " + color.New(color.FgGreen, color.Bold).Sprint(plan.Name))
fmt.Println("✅ Changed current plan to " + color.New(term.ColorHiGreen, color.Bold).Sprint(plan.Name))

fmt.Println()
term.PrintCmds("", "current")
Expand Down
6 changes: 4 additions & 2 deletions app/cli/cmd/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func changes(cmd *cobra.Command, args []string) {
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)

Expand Down Expand Up @@ -76,8 +78,8 @@ func changes(cmd *cobra.Command, args []string) {
didBuild, err := plan_exec.Build(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
return lib.MustCheckOutdatedContext(cancelOpt, true, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(true, maybeContexts)
},
}, false)

Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/continue.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func doContinue(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
},
}, "", tellBg, tellStop, tellNoBuild, true)
}
2 changes: 1 addition & 1 deletion app/cli/cmd/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func convo(cmd *cobra.Command, args []string) {
output :=
fmt.Sprintf("\n%s", convo) +
term.GetDivisionLine() +
color.New(color.Bold, color.FgCyan).Sprint(" Conversation size →") + fmt.Sprintf(" %d 🪙", totalTokens) + "\n\n"
color.New(color.Bold, term.ColorHiCyan).Sprint(" Conversation size →") + fmt.Sprintf(" %d 🪙", totalTokens) + "\n\n"

term.PageOutput(output)
}
2 changes: 1 addition & 1 deletion app/cli/cmd/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func current(cmd *cobra.Command, args []string) {
table.SetAutoWrapText(false)
table.SetHeader([]string{"Current Plan", "Updated", "Created" /*"Branches",*/, "Branch", "Context", "Convo"})

name := color.New(color.Bold, color.FgGreen).Sprint(plan.Name)
name := color.New(color.Bold, term.ColorHiGreen).Sprint(plan.Name)
branch := currentBranchesByPlanId[lib.CurrentPlanId]

row := []string{
Expand Down
11 changes: 11 additions & 0 deletions app/cli/cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ func contextRm(cmd *cobra.Command, args []string) {
deleteIds[context.Id] = true
break
}

// Check if id is a parent directory
parentDir := context.FilePath
for parentDir != "." && parentDir != "/" && parentDir != "" {
if parentDir == id {
deleteIds[context.Id] = true
break
}
parentDir = filepath.Dir(parentDir) // Move up one directory
}

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/cli/cmd/tell.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func doTell(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
CheckOutdatedContext: func(cancelOpt bool, maybeContexts []*shared.Context) (bool, bool, bool) {
return lib.MustCheckOutdatedContext(cancelOpt, false, maybeContexts)
CheckOutdatedContext: func(maybeContexts []*shared.Context) (bool, bool) {
return lib.MustCheckOutdatedContext(false, maybeContexts)
},
}, prompt, tellBg, tellStop, tellNoBuild, false)
}
Expand Down
20 changes: 18 additions & 2 deletions app/cli/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func GetPaths(baseDir, currentDir string) (*ProjectPaths, error) {
}

activePaths[relFile] = true

parentDir := relFile
for parentDir != "." && parentDir != "/" && parentDir != "" {
parentDir = filepath.Dir(parentDir)
activeDirs[parentDir] = true
}
}

errCh <- nil
Expand Down Expand Up @@ -225,6 +231,12 @@ func GetPaths(baseDir, currentDir string) (*ProjectPaths, error) {
}

activePaths[relFile] = true

parentDir := relFile
for parentDir != "." && parentDir != "/" && parentDir != "" {
parentDir = filepath.Dir(parentDir)
activeDirs[parentDir] = true
}
}

errCh <- nil
Expand Down Expand Up @@ -257,8 +269,6 @@ func GetPaths(baseDir, currentDir string) (*ProjectPaths, error) {
if ignored != nil && ignored.MatchesPath(relPath) {
return filepath.SkipDir
}

activeDirs[relPath] = true
} else {
relPath, err := filepath.Rel(currentDir, path)
if err != nil {
Expand All @@ -275,6 +285,12 @@ func GetPaths(baseDir, currentDir string) (*ProjectPaths, error) {
mu.Lock()
defer mu.Unlock()
activePaths[relPath] = true

parentDir := relPath
for parentDir != "." && parentDir != "/" && parentDir != "" {
parentDir = filepath.Dir(parentDir)
activeDirs[parentDir] = true
}
}
}

Expand Down
Loading

0 comments on commit 6536be9

Please sign in to comment.