diff --git a/ollama_agent.py b/ollama_agent.py index d42c0f5..1a9a17a 100644 --- a/ollama_agent.py +++ b/ollama_agent.py @@ -342,12 +342,13 @@ For other questions, just answer normally without tools.""" file_path = path_match.group(1) if path_match else None # Execute command patterns - check FIRST for shell commands with flags - # Shell commands like "ls -lha", "git status" should use execute - if ('ls' in text_lower or 'git' in text_lower or 'cat' in text_lower or - 'grep' in text_lower or 'find' in text_lower or 'pwd' in text_lower or - 'cd ' in text_lower or 'mkdir' in text_lower or 'rm ' in text_lower or - 'cp ' in text_lower or 'mv ' in text_lower or 'chmod' in text_lower) and ' ' in text: - return ToolCall(id='intent', name='execute', arguments={'command': text.strip()}) + # Shell commands like "ls -lha", "git status", "pwd", "echo" should use execute + shell_commands = ['ls', 'git', 'cat', 'grep', 'find', 'pwd', 'echo', 'cd', + 'mkdir', 'rm', 'cp', 'mv', 'chmod', 'head', 'tail', 'sort', 'uniq'] + # Check for command alone or with arguments + for cmd in shell_commands: + if text_lower.strip() == cmd or text_lower.startswith(cmd + ' '): + return ToolCall(id='intent', name='execute', arguments={'command': text.strip()}) # System info patterns (more comprehensive) system_patterns = [ @@ -400,17 +401,29 @@ For other questions, just answer normally without tools.""" has_write_keyword = any(k in text_lower for k in write_keywords) if has_write_keyword and file_path: - # Extract content from quoted text - content_match = re.search(r'["\']([^"\']+)["\']', text) + # Extract content - try multiple patterns + content = None + + # Pattern 1: "con dentro 'testo'" o "con 'testo'" + content_match = re.search(r'con\s+(?:dentro\s+)?["\']([^"\']+)["\']', text, re.IGNORECASE) if content_match: content = content_match.group(1) - else: - # Try to extract content between "con dentro" and quotes - content_match = re.search(r'con dentro ["\']([^"\']+)["\']', text) + + # Pattern 2: testo tra virgolette anywhere + if not content: + content_match = re.search(r'["\']([^"\']+)["\']', text) if content_match: content = content_match.group(1) - else: - content = "Content not specified" + + # Pattern 3: contenuto dopo "con" fino alla fine (senza virgolette) + if not content: + # Match: con + after_con = re.search(r'con\s+["\']?(.+?)["\']?\s*$', text, re.IGNORECASE | re.DOTALL) + if after_con: + content = after_con.group(1).strip() + + if not content: + content = "Content not specified" return ToolCall(id='intent', name='write_file', arguments={'path': file_path, 'content': content}) @@ -433,7 +446,11 @@ For other questions, just answer normally without tools.""" """ # Estrai il messaggio utente user_message = input_dict.get("messages", [])[-1] - if hasattr(user_message, 'content'): + + # Gestisci diversi formati di messaggio + if isinstance(user_message, dict): + user_content = user_message.get("content", str(user_message)) + elif hasattr(user_message, 'content'): user_content = user_message.content else: user_content = str(user_message)