on main help sign in
Merge branch 'small-fixes' of github.com:charmbracelet/crush-internal into small-fixes
commit89292e619aebc50c886acd7594ee5e2e6d46942c authorKujtim Hoxha <kujtimii.h@gmail.com> dateTue 15 Jul 2025, 11:46 (1 year ago) parent3dfac0be2bb970
2 files changed+9−22
cmd/root.go+2−18 internal/llm/agent/agent.go+7−4
cmd/root.go+2−18
@@ -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 )
internal/llm/agent/agent.go+7−4
@@ -800,11 +800,14 @@ func (a *agent) CancelAll() {
800800 a.Cancel(key.(string)) // key is sessionID
801801 return true
802802 })
803− for {
804− if a.IsBusy() {
803+
804+ timeout := time.After(5 * time.Second)
805+ for a.IsBusy() {
806+ select {
807+ case <-timeout:
808+ return
809+ default:
805810 time.Sleep(200 * time.Millisecond)
806− } else {
807− break
808811 }
809812 }
810813}