@@ -6,7 +6,6 @@ import (
12 tea "github.com/charmbracelet/bubbletea/v2"
11 tea "github.com/charmbracelet/bubbletea/v2"
@@ -86,23 +85,7 @@ to assist developers in writing, debugging, and understanding code directly from
86 slog.Error(fmt.Sprintf("Failed to create app instance: %v", err))
85 slog.Error(fmt.Sprintf("Failed to create app instance: %v", err))
87 return err
86 return err
90− // Set up shutdown handling that works for both normal exit and signal interruption
91− var shutdownOnce sync.Once
93− shutdownOnce.Do(func() {
94− slog.Info("Shutting down application")
95− app.Shutdown()
88+ defer app.Shutdown()
100− // Handle context cancellation (from signals) in a goroutine
103− slog.Info("Context cancelled, initiating shutdown")
107 // Initialize MCP tools early for both modes
90 // Initialize MCP tools early for both modes
108 initMCPTools(ctx, app, cfg)
91 initMCPTools(ctx, app, cfg)
@@ -125,6 +108,7 @@ to assist developers in writing, debugging, and understanding code directly from
125 tea.WithAltScreen(),
108 tea.WithAltScreen(),
126 tea.WithKeyReleases(),
109 tea.WithKeyReleases(),
127 tea.WithUniformKeyLayout(),
110 tea.WithUniformKeyLayout(),
111+ tea.WithContext(ctx),
128 tea.WithMouseCellMotion(), // Use cell motion instead of all motion to reduce event flooding
112 tea.WithMouseCellMotion(), // Use cell motion instead of all motion to reduce event flooding
129 tea.WithFilter(tui.MouseEventFilter), // Filter mouse events based on focus state
113 tea.WithFilter(tui.MouseEventFilter), // Filter mouse events based on focus state