on main help sign in
Merge branch 'small-fixes' of github.com:charmbracelet/crush-internal into small-fixes
89292e6Kujtim Hoxha
cmd/root.go+2−18
@@ -6,7 +6,6 @@ import (
6 "io"
6 "io"
7 "log/slog"
7 "log/slog"
8 "os"
8 "os"
9− "sync"
10 "time"
9 "time"
11
10
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
88 }
87 }
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()
88+ defer 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− }()
106
89
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
130 )
114 )
internal/llm/agent/agent.go+7−4
@@ -800,11 +800,14 @@ func (a *agent) CancelAll() {
800 a.Cancel(key.(string)) // key is sessionID
800 a.Cancel(key.(string)) // key is sessionID
801 return true
801 return true
802 })
802 })
803− for {
803+
804+ timeout := time.After(5 * time.Second)
804− if a.IsBusy() {
805+ for a.IsBusy() {
806+ select {
807+ case <-timeout:
808+ return
809+ default:
805 time.Sleep(200 * time.Millisecond)
810 time.Sleep(200 * time.Millisecond)
806− } else {
807− break
808 }
811 }
809 }
812 }
810}
813}