grokkit/cmd/chat.go
Greg Gauthier f0858e08c1 refactor(cli): simplify commands and remove TUI dependencies
- Switch chat command from Bubble Tea TUI to basic CLI with bufio.
- Hardcode Grok model in commands, remove Viper config.
- Stream responses directly in client, remove channel-based streaming.
- Add safe previews/backups in edit, simplify prompts across tools.
- Update git helper and trim unused deps in go.mod.
2026-02-28 20:17:12 +00:00

44 lines
943 B
Go

package cmd
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/internal/grok"
)
var chatCmd = &cobra.Command{
Use: "chat",
Short: "Interactive streaming chat with Grok",
Run: func(cmd *cobra.Command, args []string) {
client := grok.NewClient()
color.Cyan("Grokkit Chat — type /quit or Ctrl+C to exit\n")
history := []map[string]string{}
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print(color.YellowString("You: "))
if !scanner.Scan() {
break
}
input := strings.TrimSpace(scanner.Text())
if input == "" {
continue
}
if input == "/quit" || input == "/q" {
break
}
history = append(history, map[string]string{"role": "user", "content": input})
color.Green("Grok: ")
reply := client.Stream(history, "grok-4")
history = append(history, map[string]string{"role": "assistant", "content": reply})
}
},
}