Skip to content

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

Better handling of partial or mistyped commands in the REPL + cli 2.0.7 release notes

Dane Schneider19f5471d7dff
diff --git a/app/cli/cmd/repl.go b/app/cli/cmd/repl.go
index 20c9f169..908bfa85 100644
--- a/app/cli/cmd/repl.go
+++ b/app/cli/cmd/repl.go
@@ -401,13 +401,25 @@ func executor(in string, p *prompt.Prompt) {
cmd := parts[0]
args := parts[1:]
+ var substringNEQMatches []string
+ for replCmd := range lib.ReplCmdAliases {
+ if strings.HasPrefix(replCmd, cmd) && replCmd != cmd {
+ substringNEQMatches = append(substringNEQMatches, replCmd)
+ }
+ }
+ for _, config := range term.CliCommands {
+ if strings.HasPrefix(config.Cmd, cmd) && config.Cmd != cmd {
+ substringNEQMatches = append(substringNEQMatches, config.Cmd)
+ }
+ }
+
// Handle built-in REPL commands
switch {
- case cmd == "quit" || cmd == lib.ReplCmdAliases["quit"]:
+ case cmd == "quit" || cmd == lib.ReplCmdAliases["quit"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "quit":
lib.WriteHistory(in)
os.Exit(0)
- case cmd == "help" || cmd == lib.ReplCmdAliases["help"]:
+ case cmd == "help" || cmd == lib.ReplCmdAliases["help"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "help":
if lastBackslashIndex > 0 {
preservedBuffer += lastLine[:lastBackslashIndex]
}
@@ -418,7 +430,7 @@ func executor(in string, p *prompt.Prompt) {
}
return
- case cmd == "multi" || cmd == lib.ReplCmdAliases["multi"]:
+ case cmd == "multi" || cmd == lib.ReplCmdAliases["multi"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "multi":
if lastBackslashIndex > 0 {
preservedBuffer += lastLine[:lastBackslashIndex]
}
@@ -432,7 +444,7 @@ func executor(in string, p *prompt.Prompt) {
}
return
- case cmd == "send" || cmd == lib.ReplCmdAliases["send"]:
+ case cmd == "send" || cmd == lib.ReplCmdAliases["send"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "send":
condensedSplit := strings.Split(condensedInput, "\\s")
condensedInput = strings.TrimSpace(condensedSplit[0])
condensedInput = strings.TrimSpace(condensedInput)
@@ -448,7 +460,7 @@ func executor(in string, p *prompt.Prompt) {
return
}
- case cmd == "tell" || cmd == lib.ReplCmdAliases["tell"]:
+ case cmd == "tell" || cmd == lib.ReplCmdAliases["tell"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "tell":
if lastBackslashIndex > 0 {
preservedBuffer += lastLine[:lastBackslashIndex]
}
@@ -460,7 +472,7 @@ func executor(in string, p *prompt.Prompt) {
}
return
- case cmd == "chat" || cmd == lib.ReplCmdAliases["chat"]:
+ case cmd == "chat" || cmd == lib.ReplCmdAliases["chat"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "chat":
if lastBackslashIndex > 0 {
preservedBuffer += lastLine[:lastBackslashIndex]
}
@@ -472,7 +484,7 @@ func executor(in string, p *prompt.Prompt) {
}
return
- case cmd == "run" || cmd == lib.ReplCmdAliases["run"]:
+ case cmd == "run" || cmd == lib.ReplCmdAliases["run"] || len(substringNEQMatches) == 1 && substringNEQMatches[0] == "run":
if lastBackslashIndex > 0 {
preservedBuffer += lastLine[:lastBackslashIndex]
}
@@ -491,17 +503,49 @@ func executor(in string, p *prompt.Prompt) {
var matchedCmd string
for _, config := range term.CliCommands {
- if (cmd == config.Cmd || (config.Alias != "" && cmd == config.Alias)) && config.Repl {
+ if (cmd == config.Cmd || (config.Alias != "" && cmd == config.Alias) || len(substringNEQMatches) == 1 && substringNEQMatches[0] == config.Cmd) && config.Repl {
matchedCmd = config.Cmd
break
}
}
if matchedCmd == "" {
- for _, config := range term.CliCommands {
- if strings.HasPrefix(config.Cmd, cmd) && config.Repl {
- matchedCmd = config.Cmd
- break
+ cancelOpt := "Cancel"
+ asPrompt := cmd
+ if len(asPrompt) > 20 {
+ asPrompt = asPrompt[:20] + "..."
+ }
+ promptOpt := fmt.Sprintf("Send '%s' as a prompt to the AI model", asPrompt)
+ if len(substringNEQMatches) > 1 {
+ fmt.Println()
+ opts := []string{}
+
+ for _, match := range substringNEQMatches {
+ opts = append(opts, "\\"+match)
+ }
+ opts = append(opts, cancelOpt, promptOpt)
+ sel, err := term.SelectFromList("🤔 Did you mean to type one of these commands?", opts)
+ if err != nil {
+ color.New(term.ColorHiRed).Printf("Error selecting from list: %v\n", err)
+ }
+ if sel == cancelOpt {
+ return
+ } else if sel != promptOpt {
+ matchedCmd = strings.Replace(sel, "\\", "", 1)
+ }
+ } else if len(lines) == 1 && strings.HasPrefix(trimmedInput, "\\") {
+ showCmdsOpt := "Show available commands"
+ opts := []string{cancelOpt, showCmdsOpt, promptOpt}
+ sel, err := term.SelectFromList("🤔 Couldn't find a matching command. What do you want to do?", opts)
+ if err != nil {
+ color.New(term.ColorHiRed).Printf("Error selecting from list: %v\n", err)
+ }
+ if sel == cancelOpt {
+ return
+ } else if sel == showCmdsOpt {
+ replHelp()
+ fmt.Println()
+ return
}
}
}
diff --git a/releases/cli/versions/2.0.7.md b/releases/cli/versions/2.0.7.md
new file mode 100644
index 00000000..297b2e26
--- /dev/null
+++ b/releases/cli/versions/2.0.7.md
@@ -0,0 +1 @@
+- Better handling of partial or mistyped commands in the REPL. Rather than falling through to the AI model, a partial `\` command that matches only a single option will default to that command. If multiple commands could match, you'll be given a list of options. For input that begins with a `\` but doesn't match any command, there is now a confirmation step. This helps to prevent accidentally sending mistyped commands the model and burning tokens.
\ No newline at end of file