@@ -353,15 +353,29 @@ def run_master_loop(self):
353353 time .sleep (120 )
354354
355355 def _extract_path_from_llm_response (self , text : str ) -> str :
356- """Extracts a clean relative file path from a LLM response."""
357- cleaned_text = re .sub (r"[`\"*]" , "" , text ).strip ()
356+ """Extracts a clean relative file path from a conversational LLM response."""
357+ cleaned_text = str (re .sub (r"[`\"*]" , "" , text ).strip ())
358+
359+ matches = re .findall (r"[\w\.\-/]+\.(?:py|js|ts|html|css|json|md)" , cleaned_text )
360+
361+ base_dir = str (getattr (self , "target_dir" , "." ))
362+
363+ for match in matches :
364+ clean_match = str (match ).rstrip (".,;:'\" )" )
365+ if os .path .exists (os .path .join (base_dir , clean_match )):
366+ return str (clean_match )
367+
358368 if " " in cleaned_text :
359369 parts = cleaned_text .split ()
360370 for part in parts :
361- if "/" in part or part .endswith ((".py" , ".js" , ".ts" , ".html" , ".css" )):
362- return part
363- return parts [0 ]
364- return cleaned_text
371+ clean_part = str (part ).rstrip (".,;:'\" )" )
372+ if "/" in clean_part or clean_part .endswith (
373+ (".py" , ".js" , ".ts" , ".html" , ".css" )
374+ ):
375+ return str (clean_part )
376+ return str (parts [0 ].rstrip (".,;:'\" )" ))
377+
378+ return str (cleaned_text )
365379
366380 def _run_git_command (self , cmd : list [str ]) -> bool :
367381 """Helper to run git commands safely."""
0 commit comments