@@ -10,8 +10,10 @@ import (
1010 "syscall"
1111 "time"
1212
13+ "github.com/Zerofisher/goai/cmd/goai/tui"
1314 "github.com/Zerofisher/goai/pkg/agent"
1415 "github.com/Zerofisher/goai/pkg/config"
16+ "github.com/Zerofisher/goai/pkg/dispatcher"
1517 "github.com/Zerofisher/goai/pkg/reminder"
1618 "github.com/Zerofisher/goai/pkg/todo"
1719 "github.com/Zerofisher/goai/pkg/tools/bash"
@@ -20,6 +22,8 @@ import (
2022 "github.com/Zerofisher/goai/pkg/tools/search"
2123 todotool "github.com/Zerofisher/goai/pkg/tools/todo"
2224
25+ tea "github.com/charmbracelet/bubbletea"
26+
2327 // Import LLM providers to register their factories
2428 _ "github.com/Zerofisher/goai/pkg/llm/anthropic"
2529 _ "github.com/Zerofisher/goai/pkg/llm/openai"
@@ -68,11 +72,18 @@ func main() {
6872 fmt .Println ()
6973 }
7074
71- // Print welcome message
72- printWelcome ()
73-
74- // Run interactive loop
75- runInteractiveLoop (ctx , agent )
75+ // Check if we should use legacy interactive mode
76+ // Set GOAI_LEGACY_UI=1 to use the old readline-based interface
77+ useLegacyUI := os .Getenv ("GOAI_LEGACY_UI" ) == "1"
78+
79+ if useLegacyUI {
80+ // Use legacy interactive mode
81+ printWelcome ()
82+ runInteractiveLoop (ctx , agent )
83+ } else {
84+ // Use Bubble Tea TUI
85+ runTUI (ctx , agent , cfg )
86+ }
7687}
7788
7889// loadConfig loads the configuration from file or environment
@@ -265,4 +276,40 @@ func printHelp() {
265276 fmt .Println (" - The agent can help with code generation, debugging, and explanations" )
266277 fmt .Println (" - Use available tools to read/write files and execute commands" )
267278 fmt .Println ()
268- }
279+ }
280+
281+ // runTUI starts the Bubble Tea TUI interface
282+ func runTUI (_ context.Context , a * agent.Agent , cfg * config.Config ) {
283+ // Create TUI model
284+ model := tui .New (a , cfg )
285+
286+ // Create Bubble Tea program
287+ p := tea .NewProgram (
288+ model ,
289+ tea .WithAltScreen (), // Use alternate screen buffer
290+ tea .WithMouseCellMotion (), // Enable mouse support
291+ )
292+
293+ // Set program reference in model (for goroutine message sending)
294+ model .SetProgram (p )
295+
296+ // Configure tool observer with events options
297+ eventsOpts := dispatcher.EventsOptions {
298+ MaxOutputChars : cfg .Output .ToolOutputMaxChars ,
299+ MaskKeys : []string {
300+ "api_key" , "apikey" , "token" , "password" , "passwd" , "pwd" ,
301+ "secret" , "auth" , "key" , "access_key" , "private_key" ,
302+ "authorization" , "credential" , "credentials" ,
303+ },
304+ }
305+
306+ // Register observer with the agent
307+ observer := tui .NewObserver (p )
308+ a .SetToolObserver (observer , eventsOpts )
309+
310+ // Start the program
311+ if _ , err := p .Run (); err != nil {
312+ fmt .Printf ("Error starting TUI: %v\n " , err )
313+ os .Exit (1 )
314+ }
315+ }
0 commit comments