@@ -49,18 +49,34 @@ func NewDependencies(cfg *config.Config) (*Dependencies, error) {
4949 // Start auto-refresh to keep the indicator visible despite Claude's screen clears
5050 deps .StatusIndicator .StartAutoRefresh (deps .stopChan )
5151
52+ // Create pattern matcher and output monitor first (needed for terminal title)
53+ deps .PatternMatcher = monitor .NewSimplePatternMatcher (cfg .Patterns )
54+ outputMonitor := monitor .NewOutputMonitor (cfg , deps .PatternMatcher , deps .IdleDetector , nil ) // nil notifier for now
55+ deps .OutputMonitor = outputMonitor
56+
5257 // Create notification components
53- deps .Notifier = notification .NewNtfyClient (cfg .NtfyServer , cfg .NtfyTopic )
58+ baseNotifier := notification .NewNtfyClient (cfg .NtfyServer , cfg .NtfyTopic )
59+
60+ // Wrap with context notifier
61+ contextNotifier := notification .NewContextNotifier (baseNotifier , func () string {
62+ return outputMonitor .GetTerminalTitle ()
63+ })
64+
65+ // Wrap with backstop notifier if configured
66+ var finalNotifier notification.Notifier = contextNotifier
67+ if cfg .BackstopTimeout > 0 {
68+ finalNotifier = notification .NewBackstopNotifier (contextNotifier , cfg .BackstopTimeout )
69+ }
70+ deps .Notifier = finalNotifier
71+
5472 deps .RateLimiter = notification .NewTokenBucketRateLimiter (cfg .RateLimit .MaxMessages , cfg .RateLimit .Window )
5573 deps .NotificationManager = notification .NewManager (cfg , deps .Notifier , deps .RateLimiter )
5674
5775 // Connect status reporter to notification manager
5876 deps .NotificationManager .SetStatusReporter (deps .StatusReporter )
59-
60- // Create pattern matcher and output monitor
61- deps .PatternMatcher = monitor .NewSimplePatternMatcher (cfg .Patterns )
62- outputMonitor := monitor .NewOutputMonitor (cfg , deps .PatternMatcher , deps .IdleDetector , deps .NotificationManager )
63- deps .OutputMonitor = outputMonitor
77+
78+ // Now set the notification manager on the output monitor
79+ outputMonitor .SetNotifier (deps .NotificationManager )
6480
6581 // Connect status indicator to output monitor for screen clear detection
6682 if statusEnabled {
@@ -95,6 +111,12 @@ func (d *Dependencies) Close() {
95111 _ = d .StatusIndicator .Clear () // Best effort
96112 }
97113
114+ // Close notifiers
115+ // First try to close as backstop notifier
116+ if backstopNotifier , ok := d .Notifier .(* notification.BackstopNotifier ); ok {
117+ _ = backstopNotifier .Close ()
118+ }
119+
98120 if d .NotificationManager != nil {
99121 _ = d .NotificationManager .Close ()
100122 }
0 commit comments