@@ -6,7 +6,6 @@ import (
66 "io"
77 "log/slog"
88 "os"
9− "sync"
109 "time"
1110
1211 tea "github.com/charmbracelet/bubbletea/v2"
@@ -86,23 +85,7 @@ to assist developers in writing, debugging, and understanding code directly from
8685 slog.Error(fmt.Sprintf("Failed to create app instance: %v", err))
8786 return err
8887 }
89−
90− // Set up shutdown handling that works for both normal exit and signal interruption
91− var shutdownOnce sync.Once
92− shutdown := func() {
93− shutdownOnce.Do(func() {
94− slog.Info("Shutting down application")
95− app.Shutdown()
96− })
97− }
98− defer shutdown()
99−
100− // Handle context cancellation (from signals) in a goroutine
101− go func() {
102− <-ctx.Done()
103− slog.Info("Context cancelled, initiating shutdown")
104− shutdown()
105− }()
88+ defer app.Shutdown()
10689
10790 // Initialize MCP tools early for both modes
10891 initMCPTools(ctx, app, cfg)
@@ -125,6 +108,7 @@ to assist developers in writing, debugging, and understanding code directly from
125108 tea.WithAltScreen(),
126109 tea.WithKeyReleases(),
127110 tea.WithUniformKeyLayout(),
111+ tea.WithContext(ctx),
128112 tea.WithMouseCellMotion(), // Use cell motion instead of all motion to reduce event flooding
129113 tea.WithFilter(tui.MouseEventFilter), // Filter mouse events based on focus state
130114 )