@@ -63,6 +63,12 @@ def setup_logging(self):
6363 logging .getLogger ("urllib3" ).setLevel (logging .WARNING )
6464
6565 def setup_file_watcher (self ):
66+ if self .observer :
67+ try :
68+ self .observer .stop ()
69+ self .observer .join ()
70+ except Exception :
71+ pass
6672 try :
6773 self .observer = Observer ()
6874 watcher = FileWatcher (self .handle_file_change )
@@ -73,6 +79,7 @@ def setup_file_watcher(self):
7379 logging .error (f"Failed to start file watcher: { e } " )
7480
7581 async def process_and_broadcast_suggestion (self , sugg : Dict [str , Any ], file_content : str = "" , context_info : str = "" ):
82+ self .last_suggestion = sugg
7683 # First check safety guardrail
7784 sugg = SafetyGuardrail .check_suggestion (sugg )
7885 if sugg .get ("blocked" ):
@@ -270,6 +277,7 @@ async def process_client_message(self, data: Dict[str, Any], writer: asyncio.Str
270277 content = data .get ("content" , "" )
271278 line_idx = data .get ("line" , 0 )
272279 if file and content :
280+ self .last_focused_file = file
273281 self .session .update_file_hash (file , content )
274282
275283 # Get active line content
@@ -312,10 +320,18 @@ async def process_client_message(self, data: Dict[str, Any], writer: asyncio.Str
312320 self .session .save ()
313321
314322 if action in ["apply" , "apply_skeptic" ]:
323+ agent = self .last_suggestion .get ("agent" , "unknown" ) if getattr (self , "last_suggestion" , None ) else "unknown"
324+ hint = self .last_suggestion .get ("hint" , "" ) if getattr (self , "last_suggestion" , None ) else ""
325+ fix_code = ""
326+ if getattr (self , "last_suggestion" , None ):
327+ fix_code = self .last_suggestion .get ("skeptic_fix" if action == "apply_skeptic" else "fix" ) or ""
315328 self .replay .log_event ("fix_applied" , {
316329 "file" : self .get_last_modified_file (),
317330 "timestamp" : time .time (),
318- "version" : "skeptic" if action == "apply_skeptic" else "original"
331+ "version" : "skeptic" if action == "apply_skeptic" else "original" ,
332+ "agent" : agent ,
333+ "hint" : hint ,
334+ "fix" : fix_code
319335 })
320336 elif action == "dismiss" :
321337 self .replay .log_event ("fix_dismissed" , {
@@ -340,6 +356,8 @@ async def process_client_message(self, data: Dict[str, Any], writer: asyncio.Str
340356 asyncio .create_task (self .shutdown ())
341357
342358 def get_last_modified_file (self ) -> str :
359+ if getattr (self , "last_focused_file" , None ):
360+ return self .last_focused_file
343361 if self .session .open_files :
344362 return list (self .session .open_files .keys ())[- 1 ]
345363 return ""
0 commit comments